Skip to content

Commit

Permalink
Switch to maven-publish plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot-team committed Jun 22, 2021
1 parent 3f4ee0c commit 51a5c05
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 103 deletions.
37 changes: 17 additions & 20 deletions EventBus/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'java'

archivesBaseName = 'eventbus'
group = 'org.greenrobot'
version = '3.2.0'
java.sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -15,39 +14,37 @@ sourceSets {
}
}

apply from: rootProject.file("gradle/publish.gradle")

javadoc {
failOnError = false
title = "EventBus ${version} API"
options.bottom = 'Available under the Apache License, Version 2.0 - <i>Copyright &#169; 2012-2020 <a href="https://greenrobot.org">greenrobot.org</a>. All Rights Reserved.</i>'
}

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"
}
}
}
}
37 changes: 17 additions & 20 deletions EventBusAnnotationProcessor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'java'

archivesBaseName = 'eventbus-annotation-processor'
group = 'org.greenrobot'
version = '3.2.0'

Expand Down Expand Up @@ -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 - <i>Copyright &#169; 2015-2020 <a href="https://greenrobot.org">greenrobot.org</a>. All Rights Reserved.</i>'
}

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"
}
}
}
}
}
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.')
}
}
}
}
28 changes: 28 additions & 0 deletions eventbus-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ buildscript {

apply plugin: 'com.android.library'

group = 'org.greenrobot'
version = '3.2.0'

android {
compileSdkVersion _compileSdkVersion

Expand All @@ -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"
}
}
}
}
83 changes: 20 additions & 63 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
@@ -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')) {
Expand All @@ -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"
}
}
}
Expand Down

0 comments on commit 51a5c05

Please sign in to comment.