Skip to content

Commit

Permalink
Modernize publishing Gradle config
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers committed Sep 16, 2024
1 parent 256b8b6 commit a94ef65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 55 deletions.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ allprojects {
subprojects {
apply plugin: 'idea'
apply from: "${rootDir}/gradle/dependencies.gradle"

plugins.withId('com.android.library') {
android {
publishing {
singleVariant("release") {
withJavadocJar()
withSourcesJar()
}
}
}
}
}

task clean(type: Delete) {
Expand Down
24 changes: 5 additions & 19 deletions gradle/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = "${projectDir}/../signing-key.gpg"
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
}
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
37 changes: 1 addition & 36 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,15 @@ apply from: '../gradle/publish-root.gradle'
version = project.ext.versionName
group = project.ext.mapLibreArtifactGroupId

task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.sourceFiles
classpath = files(android.bootClasspath)
failOnError = false
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
archiveClassifier = 'dokka'
from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
archiveClassifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}

artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {

groupId this.group
artifactId project.ext.mapLibreArtifactId

from components.findByName('release')

artifact androidSourcesJar
artifact androidJavadocsJar
from components.findByName('release')

version this.version

Expand Down Expand Up @@ -70,17 +46,6 @@ afterEvaluate {
}
}


// See: https://github.com/chrisbanes/gradle-mvn-push/issues/43#issuecomment-84140513
afterEvaluate { project ->
android.libraryVariants.all { variant ->
tasks.androidJavadocs.doFirst {
classpath += files(variant.javaCompile.classpath.files)
classpath += configurations.javadocDeps
}
}
}

signing {
sign publishing.publications
}

0 comments on commit a94ef65

Please sign in to comment.