diff --git a/EventBus/build.gradle b/EventBus/build.gradle index 47456d58..ea96d39c 100644 --- a/EventBus/build.gradle +++ b/EventBus/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'java' -archivesBaseName = 'eventbus' group = 'org.greenrobot' version = '3.2.0' java.sourceCompatibility = JavaVersion.VERSION_1_8 @@ -15,8 +14,6 @@ sourceSets { } } -apply from: rootProject.file("gradle/publish.gradle") - javadoc { failOnError = false title = "EventBus ${version} API" @@ -24,30 +21,30 @@ javadoc { } task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier.set("javadoc") from 'build/docs/javadoc' } task sourcesJar(type: Jar) { + archiveClassifier.set("sources") from sourceSets.main.allSource - classifier = 'sources' -} - -artifacts { - archives jar - archives javadocJar - archives sourcesJar } -uploadArchives { - repositories { - mavenDeployer { - // Common setup is defined in publish.gradle. - - pom.project { - name 'EventBus' - description 'EventBus is a publish/subscribe event bus optimized for Android.' - } +apply from: rootProject.file("gradle/publish.gradle") +// Set project-specific properties +afterEvaluate { + publishing.publications { + mavenJava(MavenPublication) { + artifactId = "eventbus-java" + + from components.java + artifact javadocJar + artifact sourcesJar + pom { + name = "EventBus" + description = "EventBus is a publish/subscribe event bus optimized for Android." + packaging = "jar" + } } } } diff --git a/EventBusAnnotationProcessor/build.gradle b/EventBusAnnotationProcessor/build.gradle index 4ccdbb94..d5eb89e6 100644 --- a/EventBusAnnotationProcessor/build.gradle +++ b/EventBusAnnotationProcessor/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'java' -archivesBaseName = 'eventbus-annotation-processor' group = 'org.greenrobot' version = '3.2.0' @@ -28,38 +27,36 @@ sourceSets { } } -apply from: rootProject.file("gradle/publish.gradle") - javadoc { title = "EventBus Annotation Processor ${version} API" options.bottom = 'Available under the Apache License, Version 2.0 - Copyright © 2015-2020 greenrobot.org. All Rights Reserved.' } task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier.set("javadoc") from 'build/docs/javadoc' } task sourcesJar(type: Jar) { + archiveClassifier.set("sources") from sourceSets.main.allSource - classifier = 'sources' -} - -artifacts { - archives jar - archives javadocJar - archives sourcesJar } -uploadArchives { - repositories { - mavenDeployer { - // Common setup is defined in publish.gradle. - - pom.project { - name 'EventBus Annotation Processor' - description 'Precompiler for EventBus Annotations.' +apply from: rootProject.file("gradle/publish.gradle") +// Set project-specific properties +afterEvaluate { + publishing.publications { + mavenJava(MavenPublication) { + artifactId = "eventbus-annotation-processor" + + from components.java + artifact javadocJar + artifact sourcesJar + pom { + name = "EventBus Annotation Processor" + description = "Precompiler for EventBus Annotations." + packaging = "jar" } } } -} \ No newline at end of file +} diff --git a/build.gradle b/build.gradle index 30e30418..d575a7a5 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,13 @@ buildscript { ext { _compileSdkVersion = 30 // Android 11 (R) } + repositories { + mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } + } + dependencies { + classpath "io.github.gradle-nexus:publish-plugin:1.1.0" + } } allprojects { @@ -22,3 +29,20 @@ if (JavaVersion.current().isJava8Compatible()) { wrapper { distributionType = Wrapper.DistributionType.ALL } + +// Plugin to publish to Central https://github.com/gradle-nexus/publish-plugin/ +// This plugin ensures a separate, named staging repo is created for each build when publishing. +apply plugin: "io.github.gradle-nexus.publish-plugin" +nexusPublishing { + repositories { + sonatype { + if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) { + println('nexusPublishing credentials supplied.') + username = sonatypeUsername + password = sonatypePassword + } else { + println('nexusPublishing credentials NOT supplied.') + } + } + } +} diff --git a/eventbus-android/build.gradle b/eventbus-android/build.gradle index cdb59fb9..601e0c9a 100644 --- a/eventbus-android/build.gradle +++ b/eventbus-android/build.gradle @@ -12,6 +12,9 @@ buildscript { apply plugin: 'com.android.library' +group = 'org.greenrobot' +version = '3.2.0' + android { compileSdkVersion _compileSdkVersion @@ -30,3 +33,28 @@ android { dependencies { implementation project(":eventbus") } + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + archiveClassifier.set("sources") +} + +apply from: rootProject.file("gradle/publish.gradle") +// Set project-specific properties +// https://developer.android.com/studio/build/maven-publish-plugin +afterEvaluate { + publishing.publications { + mavenJava(MavenPublication) { + artifactId = "eventbus" + + from components.release + artifact sourcesJar + + pom { + name = "EventBus" + description = "EventBus is a publish/subscribe event bus optimized for Android." + packaging = "aar" + } + } + } +} diff --git a/gradle/publish.gradle b/gradle/publish.gradle index a887ff3a..5420dd44 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -1,18 +1,8 @@ // Configures common publishing settings. -apply plugin: "maven" +apply plugin: "maven-publish" apply plugin: "signing" -configurations { - deployerJars -} - -dependencies { - // Using an older version to remain compatible with Wagon API used by Gradle/Maven. - deployerJars 'org.apache.maven.wagon:wagon-webdav-jackrabbit:3.2.0' - deployerJars 'org.apache.maven.wagon:wagon-ftp:3.3.2' -} - signing { if (project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')) { @@ -22,71 +12,38 @@ signing { } } -// Use afterEvaluate or dependencies might be lost in the generated POM. -afterEvaluate { project -> - uploadArchives { - repositories { - mavenDeployer { - def preferredRepo = project.findProperty('preferredRepo') - println "preferredRepo=$preferredRepo" - - if (preferredRepo == 'local') { - repository url: repositories.mavenLocal().url - } else if (preferredRepo != null - && project.hasProperty('preferredUsername') - && project.hasProperty('preferredPassword')) { - configuration = configurations.deployerJars - repository(url: repositoryUrl) { - authentication(userName: preferredUsername, password: preferredPassword) - } - } else if (project.hasProperty('sonatypeUsername') - && project.hasProperty('sonatypePassword')) { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - def isSnapshot = version.endsWith('-SNAPSHOT') - def sonatypeRepositoryUrl = isSnapshot - ? "https://oss.sonatype.org/content/repositories/snapshots/" - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" - repository(url: sonatypeRepositoryUrl) { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - } else { - println "Deployment settings missing/incomplete for ${project.name}." - } - - // Common properties, projects still need to set name and description. - pom.project { - packaging 'jar' - url 'https://greenrobot.org/eventbus/' +// https://developer.android.com/studio/build/maven-publish-plugin +// Because the Android components are created only during the afterEvaluate phase, you must +// configure your publications using the afterEvaluate() lifecycle method. +afterEvaluate { + publishing { + publications { + // Note: Sonatype repo created by publish-plugin, see root build.gradle. + mavenJava(MavenPublication) { + pom { + url = "https://greenrobot.org/eventbus/" scm { - url 'https://github.com/greenrobot/EventBus' - connection 'scm:git@github.com:greenrobot/EventBus.git' - developerConnection 'scm:git@github.com:greenrobot/EventBus.git' - } - - licenses { - license { - name 'The Apache Software License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } + connection = "scm:git@github.com:greenrobot/EventBus.git" + developerConnection = "scm:git@github.com:greenrobot/EventBus.git" + url = "https://github.com/greenrobot/EventBus" } developers { developer { - id 'greenrobot' - name 'greenrobot' + id = "greenrobot" + name = "greenrobot" } } issueManagement { - system 'GitHub Issues' - url 'https://github.com/greenrobot/EventBus/issues' + system = "https://github.com/greenrobot/EventBus/issues" + url = "https://github.com/greenrobot/EventBus/issues" } organization { - name 'greenrobot' - url 'https://greenrobot.org' + name = "greenrobot" + url = "https://greenrobot.org" } } }