Skip to content

Commit 51a5c05

Browse files
Switch to maven-publish plugin.
1 parent 3f4ee0c commit 51a5c05

File tree

5 files changed

+106
-103
lines changed

5 files changed

+106
-103
lines changed

EventBus/build.gradle

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'java'
22

3-
archivesBaseName = 'eventbus'
43
group = 'org.greenrobot'
54
version = '3.2.0'
65
java.sourceCompatibility = JavaVersion.VERSION_1_8
@@ -15,39 +14,37 @@ sourceSets {
1514
}
1615
}
1716

18-
apply from: rootProject.file("gradle/publish.gradle")
19-
2017
javadoc {
2118
failOnError = false
2219
title = "EventBus ${version} API"
2320
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>'
2421
}
2522

2623
task javadocJar(type: Jar, dependsOn: javadoc) {
27-
classifier = 'javadoc'
24+
archiveClassifier.set("javadoc")
2825
from 'build/docs/javadoc'
2926
}
3027

3128
task sourcesJar(type: Jar) {
29+
archiveClassifier.set("sources")
3230
from sourceSets.main.allSource
33-
classifier = 'sources'
34-
}
35-
36-
artifacts {
37-
archives jar
38-
archives javadocJar
39-
archives sourcesJar
4031
}
4132

42-
uploadArchives {
43-
repositories {
44-
mavenDeployer {
45-
// Common setup is defined in publish.gradle.
46-
47-
pom.project {
48-
name 'EventBus'
49-
description 'EventBus is a publish/subscribe event bus optimized for Android.'
50-
}
33+
apply from: rootProject.file("gradle/publish.gradle")
34+
// Set project-specific properties
35+
afterEvaluate {
36+
publishing.publications {
37+
mavenJava(MavenPublication) {
38+
artifactId = "eventbus-java"
39+
40+
from components.java
41+
artifact javadocJar
42+
artifact sourcesJar
43+
pom {
44+
name = "EventBus"
45+
description = "EventBus is a publish/subscribe event bus optimized for Android."
46+
packaging = "jar"
47+
}
5148
}
5249
}
5350
}
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'java'
22

3-
archivesBaseName = 'eventbus-annotation-processor'
43
group = 'org.greenrobot'
54
version = '3.2.0'
65

@@ -28,38 +27,36 @@ sourceSets {
2827
}
2928
}
3029

31-
apply from: rootProject.file("gradle/publish.gradle")
32-
3330
javadoc {
3431
title = "EventBus Annotation Processor ${version} API"
3532
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>'
3633
}
3734

3835
task javadocJar(type: Jar, dependsOn: javadoc) {
39-
classifier = 'javadoc'
36+
archiveClassifier.set("javadoc")
4037
from 'build/docs/javadoc'
4138
}
4239

4340
task sourcesJar(type: Jar) {
41+
archiveClassifier.set("sources")
4442
from sourceSets.main.allSource
45-
classifier = 'sources'
46-
}
47-
48-
artifacts {
49-
archives jar
50-
archives javadocJar
51-
archives sourcesJar
5243
}
5344

54-
uploadArchives {
55-
repositories {
56-
mavenDeployer {
57-
// Common setup is defined in publish.gradle.
58-
59-
pom.project {
60-
name 'EventBus Annotation Processor'
61-
description 'Precompiler for EventBus Annotations.'
45+
apply from: rootProject.file("gradle/publish.gradle")
46+
// Set project-specific properties
47+
afterEvaluate {
48+
publishing.publications {
49+
mavenJava(MavenPublication) {
50+
artifactId = "eventbus-annotation-processor"
51+
52+
from components.java
53+
artifact javadocJar
54+
artifact sourcesJar
55+
pom {
56+
name = "EventBus Annotation Processor"
57+
description = "Precompiler for EventBus Annotations."
58+
packaging = "jar"
6259
}
6360
}
6461
}
65-
}
62+
}

build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ buildscript {
22
ext {
33
_compileSdkVersion = 30 // Android 11 (R)
44
}
5+
repositories {
6+
mavenCentral()
7+
maven { url "https://plugins.gradle.org/m2/" }
8+
}
9+
dependencies {
10+
classpath "io.github.gradle-nexus:publish-plugin:1.1.0"
11+
}
512
}
613

714
allprojects {
@@ -22,3 +29,20 @@ if (JavaVersion.current().isJava8Compatible()) {
2229
wrapper {
2330
distributionType = Wrapper.DistributionType.ALL
2431
}
32+
33+
// Plugin to publish to Central https://github.com/gradle-nexus/publish-plugin/
34+
// This plugin ensures a separate, named staging repo is created for each build when publishing.
35+
apply plugin: "io.github.gradle-nexus.publish-plugin"
36+
nexusPublishing {
37+
repositories {
38+
sonatype {
39+
if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) {
40+
println('nexusPublishing credentials supplied.')
41+
username = sonatypeUsername
42+
password = sonatypePassword
43+
} else {
44+
println('nexusPublishing credentials NOT supplied.')
45+
}
46+
}
47+
}
48+
}

eventbus-android/build.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ buildscript {
1212

1313
apply plugin: 'com.android.library'
1414

15+
group = 'org.greenrobot'
16+
version = '3.2.0'
17+
1518
android {
1619
compileSdkVersion _compileSdkVersion
1720

@@ -30,3 +33,28 @@ android {
3033
dependencies {
3134
implementation project(":eventbus")
3235
}
36+
37+
task sourcesJar(type: Jar) {
38+
from android.sourceSets.main.java.srcDirs
39+
archiveClassifier.set("sources")
40+
}
41+
42+
apply from: rootProject.file("gradle/publish.gradle")
43+
// Set project-specific properties
44+
// https://developer.android.com/studio/build/maven-publish-plugin
45+
afterEvaluate {
46+
publishing.publications {
47+
mavenJava(MavenPublication) {
48+
artifactId = "eventbus"
49+
50+
from components.release
51+
artifact sourcesJar
52+
53+
pom {
54+
name = "EventBus"
55+
description = "EventBus is a publish/subscribe event bus optimized for Android."
56+
packaging = "aar"
57+
}
58+
}
59+
}
60+
}

gradle/publish.gradle

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
// Configures common publishing settings.
22

3-
apply plugin: "maven"
3+
apply plugin: "maven-publish"
44
apply plugin: "signing"
55

6-
configurations {
7-
deployerJars
8-
}
9-
10-
dependencies {
11-
// Using an older version to remain compatible with Wagon API used by Gradle/Maven.
12-
deployerJars 'org.apache.maven.wagon:wagon-webdav-jackrabbit:3.2.0'
13-
deployerJars 'org.apache.maven.wagon:wagon-ftp:3.3.2'
14-
}
15-
166
signing {
177
if (project.hasProperty('signing.keyId') && project.hasProperty('signing.password') &&
188
project.hasProperty('signing.secretKeyRingFile')) {
@@ -22,71 +12,38 @@ signing {
2212
}
2313
}
2414

25-
// Use afterEvaluate or dependencies might be lost in the generated POM.
26-
afterEvaluate { project ->
27-
uploadArchives {
28-
repositories {
29-
mavenDeployer {
30-
def preferredRepo = project.findProperty('preferredRepo')
31-
println "preferredRepo=$preferredRepo"
32-
33-
if (preferredRepo == 'local') {
34-
repository url: repositories.mavenLocal().url
35-
} else if (preferredRepo != null
36-
&& project.hasProperty('preferredUsername')
37-
&& project.hasProperty('preferredPassword')) {
38-
configuration = configurations.deployerJars
39-
repository(url: repositoryUrl) {
40-
authentication(userName: preferredUsername, password: preferredPassword)
41-
}
42-
} else if (project.hasProperty('sonatypeUsername')
43-
&& project.hasProperty('sonatypePassword')) {
44-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
45-
def isSnapshot = version.endsWith('-SNAPSHOT')
46-
def sonatypeRepositoryUrl = isSnapshot
47-
? "https://oss.sonatype.org/content/repositories/snapshots/"
48-
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
49-
repository(url: sonatypeRepositoryUrl) {
50-
authentication(userName: sonatypeUsername, password: sonatypePassword)
51-
}
52-
} else {
53-
println "Deployment settings missing/incomplete for ${project.name}."
54-
}
55-
56-
// Common properties, projects still need to set name and description.
57-
pom.project {
58-
packaging 'jar'
59-
url 'https://greenrobot.org/eventbus/'
15+
// https://developer.android.com/studio/build/maven-publish-plugin
16+
// Because the Android components are created only during the afterEvaluate phase, you must
17+
// configure your publications using the afterEvaluate() lifecycle method.
18+
afterEvaluate {
19+
publishing {
20+
publications {
21+
// Note: Sonatype repo created by publish-plugin, see root build.gradle.
22+
mavenJava(MavenPublication) {
23+
pom {
24+
url = "https://greenrobot.org/eventbus/"
6025

6126
scm {
62-
url 'https://github.com/greenrobot/EventBus'
63-
connection 'scm:[email protected]:greenrobot/EventBus.git'
64-
developerConnection 'scm:[email protected]:greenrobot/EventBus.git'
65-
}
66-
67-
licenses {
68-
license {
69-
name 'The Apache Software License, Version 2.0'
70-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
71-
distribution 'repo'
72-
}
27+
connection = "scm:[email protected]:greenrobot/EventBus.git"
28+
developerConnection = "scm:[email protected]:greenrobot/EventBus.git"
29+
url = "https://github.com/greenrobot/EventBus"
7330
}
7431

7532
developers {
7633
developer {
77-
id 'greenrobot'
78-
name 'greenrobot'
34+
id = "greenrobot"
35+
name = "greenrobot"
7936
}
8037
}
8138

8239
issueManagement {
83-
system 'GitHub Issues'
84-
url 'https://github.com/greenrobot/EventBus/issues'
40+
system = "https://github.com/greenrobot/EventBus/issues"
41+
url = "https://github.com/greenrobot/EventBus/issues"
8542
}
8643

8744
organization {
88-
name 'greenrobot'
89-
url 'https://greenrobot.org'
45+
name = "greenrobot"
46+
url = "https://greenrobot.org"
9047
}
9148
}
9249
}

0 commit comments

Comments
 (0)