Skip to content

Commit

Permalink
Merge pull request #118 from velocitycareerlabs/VL-7885-rewrite-gradle
Browse files Browse the repository at this point in the history
rewrite gradle
  • Loading branch information
michaelavoyan authored Jun 26, 2024
2 parents 0371831 + d53d0c5 commit 9a94514
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 112 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/android-sdk-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ env:
GRADLE_VERSION: "8.4"
JAVA_VERSION: "17"
ARTIFACT_PATH: "VCL/build/outputs"
ANDROID_NEXUS_OSSRH_TOKEN_USERNAME: ${{ secrets.ANDROID_NEXUS_OSSRH_TOKEN_USERNAME }}
ANDROID_NEXUS_OSSRH_TOKEN_PASSWORD: ${{ secrets.ANDROID_NEXUS_OSSRH_TOKEN_PASSWORD }}
ANDROID_NEXUS_SIGNING_KEY_ID: ${{ secrets.ANDROID_NEXUS_SIGNING_KEY_ID }}
ANDROID_NEXUS_SIGNING_PASSWORD: ${{ secrets.ANDROID_NEXUS_SIGNING_PASSWORD }}
ANDROID_NEXUS_STAGING_PROFILE_ID: ${{ secrets.ANDROID_NEXUS_STAGING_PROFILE_ID }}
ANDROID_NEXUS_PRIVATE_KEY: ${{ secrets.ANDROID_NEXUS_PRIVATE_KEY }}
jobs:
test-android-sdk:
runs-on: ubuntu-latest
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/android-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ jobs:
run: ./gradlew assemble${{ env.RELEASE_TAG }}
env:
RELEASE_TAG: ${{ env.GLOBAL_ENV == 'prod' && format('{0}', 'Release' ) || 'Rc' }}
ANDROID_NEXUS_OSSRH_TOKEN_USERNAME: ${{ secrets.ANDROID_NEXUS_OSSRH_TOKEN_USERNAME }}
ANDROID_NEXUS_OSSRH_TOKEN_PASSWORD: ${{ secrets.ANDROID_NEXUS_OSSRH_TOKEN_PASSWORD }}
ANDROID_NEXUS_SIGNING_KEY_ID: ${{ secrets.ANDROID_NEXUS_SIGNING_KEY_ID }}
ANDROID_NEXUS_SIGNING_PASSWORD: ${{ secrets.ANDROID_NEXUS_SIGNING_PASSWORD }}
ANDROID_NEXUS_STAGING_PROFILE_ID: ${{ secrets.ANDROID_NEXUS_STAGING_PROFILE_ID }}
ANDROID_NEXUS_PRIVATE_KEY: ${{ secrets.ANDROID_NEXUS_PRIVATE_KEY }}
# Convert artifact to lowercase
- name: Rename artifact to lowercase
run: mv ${{ env.ARTIFACT_PATH}}/${{ env.PACKAGE_TYPE }}/VCL-${{ env.RELEASE_TAG }}.${{ env.PACKAGE_TYPE }} ${{ env.ARTIFACT_PATH }}/${{ env.PACKAGE_TYPE }}/vcl-${{ env.RELEASE_TAG }}.${{ env.PACKAGE_TYPE }}
Expand All @@ -82,7 +76,6 @@ jobs:
ANDROID_NEXUS_SIGNING_KEY_ID: ${{ secrets.ANDROID_NEXUS_SIGNING_KEY_ID }}
ANDROID_NEXUS_SIGNING_PASSWORD: ${{ secrets.ANDROID_NEXUS_SIGNING_PASSWORD }}
ANDROID_NEXUS_STAGING_PROFILE_ID: ${{ secrets.ANDROID_NEXUS_STAGING_PROFILE_ID }}
ANDROID_NEXUS_PRIVATE_KEY: ${{ secrets.ANDROID_NEXUS_PRIVATE_KEY }}
# Upload Artifacts
- name: Upload Artifact
if: success()
Expand Down
112 changes: 45 additions & 67 deletions VCL/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ plugins {

android {
compileSdk 34
// buildToolsVersion "30.0.3"
namespace 'io.velocitycareerlabs'

defaultConfig {
Expand Down Expand Up @@ -88,31 +87,23 @@ def getGroupId = { ->

tasks.register('androidSourcesJar', Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
// For Android libraries
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
} else {
// For pure Kotlin libraries, in case you have them
from sourceSets.main.java.srcDirs
from sourceSets.main.kotlin.srcDirs
}
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
}

artifacts {
archives androidSourcesJar
archives tasks.named('androidSourcesJar')
}

afterEvaluate {
publishing {
publications {
rc(MavenPublication) {
groupId getGroupId()
artifactId getArtifactId()
version getVersionName()
create('rc', MavenPublication) {
groupId = getGroupId()
artifactId = getArtifactId()
version = getVersionName()

// Main artifact
if (project.plugins.findPlugin("com.android.library")) {
if (project.plugins.hasPlugin("com.android.library")) {
artifact("$buildDir/outputs/aar/${project.name}-release.aar") {
builtBy tasks.named('assembleRelease')
}
Expand All @@ -122,46 +113,38 @@ afterEvaluate {
}
}

// Sources jar artifact
artifact(tasks.named('androidSourcesJar'))

// Mostly self-explanatory metadata
pom {
name = getArtifactId()
// Library description
description = 'Velocity Career Labs Android library'
// Library Github URL
url = 'https://github.com/velocitycareerlabs/WalletAndroid'
name.set(getArtifactId())
description.set('Velocity Career Labs Android library')
url.set('https://github.com/velocitycareerlabs/WalletAndroid')
licenses {
license {
name = 'Apache License 2.0'
// Library license
url = 'https://github.com/velocitycareerlabs/WalletAndroid/blob/dev/VCL/LICENSE'
name.set('Apache License 2.0')
url.set('https://github.com/velocitycareerlabs/WalletAndroid/blob/dev/VCL/LICENSE')
}
}
developers {
developer {
id = 'velocitycareerlabs'
name = 'Michael Avoyan'
email = '[email protected]'
id.set('velocitycareerlabs')
name.set('Michael Avoyan')
email.set('[email protected]')
}
}

scm {
// Library info on Github
connection = 'scm:github.com/velocitycareerlabs/WalletAndroid.git'
developerConnection = 'scm:git:ssh://github.com/velocitycareerlabs/WalletAndroid.git'
url = 'https://github.com/velocitycareerlabs/WalletAndroid'
connection.set('scm:github.com/velocitycareerlabs/WalletAndroid.git')
developerConnection.set('scm:git:ssh://github.com/velocitycareerlabs/WalletAndroid.git')
url.set('https://github.com/velocitycareerlabs/WalletAndroid')
}
}
}
release(MavenPublication) {
groupId getGroupId()
artifactId getArtifactId()
version getVersionName()
create('release', MavenPublication) {
groupId = getGroupId()
artifactId = getArtifactId()
version = getVersionName()

// Main artifact
if (project.plugins.findPlugin("com.android.library")) {
if (project.plugins.hasPlugin("com.android.library")) {
artifact("$buildDir/outputs/aar/${project.name}-release.aar") {
builtBy tasks.named('assembleRelease')
}
Expand All @@ -171,36 +154,29 @@ afterEvaluate {
}
}

// Sources jar artifact
artifact(tasks.named('androidSourcesJar'))

// Mostly self-explanatory metadata
pom {
name = getArtifactId()
// Library description
description = 'Velocity Career Labs Android library'
// Library Github URL
url = 'https://github.com/velocitycareerlabs/WalletAndroid'
name.set(getArtifactId())
description.set('Velocity Career Labs Android library')
url.set('https://github.com/velocitycareerlabs/WalletAndroid')
licenses {
license {
name = 'Apache License 2.0'
// Library license
url = 'https://github.com/velocitycareerlabs/WalletAndroid/blob/dev/VCL/LICENSE'
name.set('Apache License 2.0')
url.set('https://github.com/velocitycareerlabs/WalletAndroid/blob/dev/VCL/LICENSE')
}
}
developers {
developer {
id = 'velocitycareerlabs'
name = 'Michael Avoyan'
email = '[email protected]'
id.set('velocitycareerlabs')
name.set('Michael Avoyan')
email.set('[email protected]')
}
}

scm {
// Library info on Github
connection = 'scm:github.com/velocitycareerlabs/WalletAndroid.git'
developerConnection = 'scm:git:ssh://github.com/velocitycareerlabs/WalletAndroid.git'
url = 'https://github.com/velocitycareerlabs/WalletAndroid'
connection.set('scm:github.com/velocitycareerlabs/WalletAndroid.git')
developerConnection.set('scm:git:ssh://github.com/velocitycareerlabs/WalletAndroid.git')
url.set('https://github.com/velocitycareerlabs/WalletAndroid')
}
}
}
Expand All @@ -213,21 +189,23 @@ afterEvaluate {
rootProject.ext.signingPrivateKey,
rootProject.ext.signingPassword
)
sign publishing.publications
sign(publishing.publications)
// sign(publishing.publications['rc'])
// sign(publishing.publications['release'])
}

tasks.named('generateMetadataFileForRcPublication') {
dependsOn tasks.named('androidSourcesJar')
dependsOn(tasks.named('androidSourcesJar'))
}

tasks.named("publishRcPublicationToSonatypeRepository").configure {
dependsOn tasks.named("signRcPublication")
dependsOn tasks.named("signReleasePublication")
tasks.named("publishRcPublicationToSonatypeRepository") {
dependsOn(tasks.named("signRcPublication"))
dependsOn(tasks.named("signReleasePublication"))
}

tasks.named("publishReleasePublicationToSonatypeRepository").configure {
dependsOn tasks.named("signReleasePublication")
dependsOn tasks.named("signRcPublication")
tasks.named("publishReleasePublicationToSonatypeRepository") {
dependsOn(tasks.named("signReleasePublication"))
dependsOn(tasks.named("signRcPublication"))
}
}

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ allprojects {
google()
mavenCentral()
maven {
url "${getLayout().getBuildDirectory()}/VCL"
url "${layout.buildDirectory.get()}/VCL"
}
}
}

tasks.register('clean', Delete) {
delete rootProject.getLayout().getBuildDirectory()
delete rootProject.layout.buildDirectory.get()
}
66 changes: 30 additions & 36 deletions publish-core.gradle
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
def propertiesFilePath = '/Volumes/Keybase/team/velocitycareers/mobile/android/maven/nexus.properties'
def propertiesFilePath_alternative = 'nexus.properties'
def propertiesFilePathAlternative = 'nexus.properties'

def propertiesFile = new File(propertiesFilePath)
def propertiesFile_alternative = new File(propertiesFilePath_alternative)
static def loadProperties(filePath) {
def properties = new Properties()
def file = new File(filePath)
if (file.exists()) {
file.withInputStream { stream ->
properties.load(stream)
}
}
return properties
}

def properties = new Properties()
def properties = loadProperties(propertiesFilePath)
if (properties.isEmpty()) {
properties = loadProperties(propertiesFilePathAlternative)
}

if (propertiesFile.exists()) {
try {
properties.load(new FileInputStream(propertiesFile))
} catch (IOException e) {
e.printStackTrace()
}
} else if (propertiesFile_alternative.exists()) {
try {
properties.load(new FileInputStream(propertiesFile_alternative))
} catch (IOException e) {
e.printStackTrace()
}
} else {
println "Properties file not found: $propertiesFilePath or $propertiesFilePath_alternative"
if (properties.isEmpty()) {
println "Properties file not found: $propertiesFilePath or $propertiesFilePathAlternative"
}

ext {
signingKeyId = (System.getenv("ANDROID_NEXUS_SIGNING_KEY_ID") ?: properties["signingKeyId"]) ?: println("signingKeyId was NOT found")
signingPassword = (System.getenv("ANDROID_NEXUS_SIGNING_PASSWORD") ?: properties["signingPassword"]) ?: println("signingPassword was NOT found")
// ossrhUsername = (System.getenv("ANDROID_NEXUS_OSSRH_USERNAME") ?: properties["ossrhUsername"]) ?: println("ossrhUsername was NOT found")
// ossrhPassword = (System.getenv("ANDROID_NEXUS_OSSRH_PASSWORD") ?: properties["ossrhPassword"]) ?: println("ossrhPassword was NOT found")
ossrhTokenUsername = (System.getenv("ANDROID_NEXUS_OSSRH_TOKEN_USERNAME") ?: properties["ossrhTokenUsername"]) ?: println("ossrhTokenUsername was NOT found")
ossrhTokenPassword = (System.getenv("ANDROID_NEXUS_OSSRH_TOKEN_PASSWORD") ?: properties["ossrhTokenPassword"]) ?: println("ossrhTokenPassword was NOT found")
sonatypeStagingProfileId = (System.getenv("ANDROID_NEXUS_STAGING_PROFILE_ID") ?: properties["stagingProfileId"]) ?: println("stagingProfileId was NOT found")
signingPrivateKey = (System.getenv("ANDROID_NEXUS_PRIVATE_KEY") ?: properties["signingPrivateKey"]) ?: println("signingPrivateKey was NOT found")
signingKeyId = System.getenv("ANDROID_NEXUS_SIGNING_KEY_ID") ?: properties.getProperty("signingKeyId") ?: println("signingKeyId was NOT found")
signingPassword = System.getenv("ANDROID_NEXUS_SIGNING_PASSWORD") ?: properties.getProperty("signingPassword") ?: println("signingPassword was NOT found")
ossrhTokenUsername = System.getenv("ANDROID_NEXUS_OSSRH_TOKEN_USERNAME") ?: properties.getProperty("ossrhTokenUsername") ?: println("ossrhTokenUsername was NOT found")
ossrhTokenPassword = System.getenv("ANDROID_NEXUS_OSSRH_TOKEN_PASSWORD") ?: properties.getProperty("ossrhTokenPassword") ?: println("ossrhTokenPassword was NOT found")
sonatypeStagingProfileId = System.getenv("ANDROID_NEXUS_STAGING_PROFILE_ID") ?: properties.getProperty("stagingProfileId") ?: println("stagingProfileId was NOT found")
signingPrivateKey = System.getenv("ANDROID_NEXUS_PRIVATE_KEY") ?: properties.getProperty("signingPrivateKey") ?: println("signingPrivateKey was NOT found")
}

// println("signingKeyId: ${signingKeyId}")
// println("signingPassword: ${signingPassword}")
//
// println("ossrhPassword: ${ossrhPassword}")
// println("sonatypeStagingProfileId: ${sonatypeStagingProfileId}")
// println("signingPrivateKey: ${signingPrivateKey}")

nexusPublishing {
repositories {
sonatype {
Expand All @@ -52,6 +42,10 @@ nexusPublishing {
}
}

// Create custom tasks for publishing
tasks.register('publishRelease') { dependsOn([':VCL:publishReleasePublicationToSonatypeRepository']) }
tasks.register('publishRc') { dependsOn([':VCL:publishRcPublicationToSonatypeRepository']) }
tasks.register('publishRelease') {
dependsOn(':VCL:publishReleasePublicationToSonatypeRepository')
}

tasks.register('publishRc') {
dependsOn(':VCL:publishRcPublicationToSonatypeRepository')
}

0 comments on commit 9a94514

Please sign in to comment.