15
15
*/
16
16
/*
17
17
* A note about publishing and signing.
18
- * Maven central requires that artifacts be signed. And upload is done to Sonatype .
18
+ * Maven central requires that artifacts be signed. And upload is done via Maven Central Portal .
19
19
* To publish you will need these environment variables defined:
20
- * SONATYPE_TOKEN_USERNAME
21
- * SONATYPE_TOKEN_PASSWORD
20
+ * MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME
21
+ * MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD
22
22
* MAVEN_GPG_PRIVATE_KEY
23
23
* MAVEN_GPG_PASSPHRASE
24
- * Suggestion is to put these in a shell script with restricted read permissions, then source it before calling
25
- * ./gradlew publish.
24
+ * If run manually, the suggestion is to put these in a shell script with restricted read permissions,
25
+ * then source it before calling ./gradlew
26
+ * If run from a Github action, make sure these environment variables are defined.
26
27
*/
27
28
plugins {
28
29
id ' java'
@@ -58,6 +59,7 @@ allprojects {
58
59
59
60
tasks. withType(Javadoc ) {
60
61
options. encoding = ' UTF-8'
62
+ options. addStringOption(' Xdoclint:none' , ' -quiet' )
61
63
}
62
64
63
65
// All projects that include the 'java` plugin will have a Test task by default.
@@ -82,16 +84,6 @@ subprojects {
82
84
apply plugin : ' java'
83
85
apply plugin : libs. plugins. spotless. get(). pluginId
84
86
85
- // Cannot publish a SNAPSHOT. The provided sonatype url will not accept it.
86
- tasks. withType(PublishToMavenRepository ). all { task ->
87
- task. onlyIf {
88
- if (project. version. toString(). contains(' SNAPSHOT' )) {
89
- throw new GradleException (" Publishing is not allowed for SNAPSHOT versions. Currently " + project. version)
90
- }
91
- true
92
- }
93
- }
94
-
95
87
task javadocJar(type : Jar ) {
96
88
archiveClassifier. set(' javadoc' )
97
89
from javadoc
@@ -111,24 +103,29 @@ subprojects {
111
103
112
104
// These modules require the same publishing configuration, apart from the name of the module
113
105
// Also we want to limit artefact publishing to these modules.
114
- if (project. name == ' main' ||
115
- project. name == ' core' ||
116
- project. name == ' model' ) {
106
+ if (project. name == ' main'
107
+ || project. name == ' core'
108
+ || project. name == ' model'
109
+ ) {
117
110
def fullProjectName = ' gtfs-validator-' + project. name
118
111
119
112
afterEvaluate {
120
113
publishing {
121
114
repositories {
122
- // This is the sonatype staging repo for maven.
123
- // Once uploaded, the repo needs to be manually closed, which will trigger acceptance tests for
124
- // maven central (but not transfer yet).
125
- // Once successfully closed, the repo is available for testing.
126
- // After testing, it can be manually promoted on the sonatype site, which will then publish to maven central.
127
115
maven {
128
- url = ' https://s01.oss.sonatype.org/service/local/staging/deploy/maven2'
129
- credentials {
130
- username System . getenv(" SONATYPE_TOKEN_USERNAME" )
131
- password System . getenv(" SONATYPE_TOKEN_PASSWORD" )
116
+ // Snapshot uses a different repository than release.
117
+ // The publish in that case will upload to Maven Central snapshot repository.
118
+ if (version. endsWith(' SNAPSHOT' )) {
119
+ url = ' https://central.sonatype.com/repository/maven-snapshots/'
120
+ credentials {
121
+ username = System . getenv(" MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME" )
122
+ password = System . getenv(" MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD" )
123
+ }
124
+ } else {
125
+ // For releases, the publish task does not upload to MavenCentral.
126
+ // It just the artifacts directory hierarchy on the local disk,
127
+ // The actual zipping and uploading is done in the publishToMavenCentral task.
128
+ url = " ${ buildDir} /local-repo"
132
129
}
133
130
}
134
131
}
@@ -172,9 +169,51 @@ subprojects {
172
169
useInMemoryPgpKeys(System . getenv(' MAVEN_GPG_PRIVATE_KEY' ), System . getenv(' MAVEN_GPG_PASSPHRASE' ))
173
170
sign publishing. publications. mavenJava
174
171
}
172
+
173
+
174
+ tasks. register(' publishToMavenCentral' ) {
175
+ // We want to do call the publish task only if the version is a release (ie not a snapshot).
176
+ // Without this conditional, with a snapshot it would do the publish first, then throw the Exception below.
177
+ // But since the dependsOn is within the conditional, the dependency is not created for snapshot versions
178
+ // so the publish in that case is never executed.
179
+ if (! version. toString(). endsWith(' SNAPSHOT' )) {
180
+ dependsOn tasks. publish
181
+ }
182
+ doFirst {
183
+ if (version. toString(). endsWith(' SNAPSHOT' )) {
184
+ throw new GradleException (" Version \" " + version +
185
+ " \" is a snapshot. Cannot publish to Maven Central" )
186
+ }
187
+ }
188
+
189
+ doLast {
190
+ exec {
191
+ workingDir project. projectDir
192
+ commandLine ' bash' , " ${ project.rootDir} /scripts/publish_to_maven_central.sh" , project. name, project. version
193
+ }
194
+ }
195
+ }
196
+
197
+ tasks. register(' publishToSnapshotRepository' ) {
198
+ // We want to do call the publish task only if the version is a snapshot.
199
+ // Without this conditional, with a release it would do the publish first, then throw the Exception below.
200
+ // But since the dependsOn is within the conditional, the dependency is not created for release versions
201
+ // so the publish in that case is never executed.
202
+ if (version. toString(). endsWith(' SNAPSHOT' )) {
203
+ dependsOn tasks. publish
204
+ }
205
+ doFirst {
206
+ if (! version. toString(). endsWith(' SNAPSHOT' )) {
207
+ throw new GradleException (" Version \" " + version +
208
+ " \" is a NOT a snapshot. Cannot publish to the snapshot repository" )
209
+ }
210
+ }
211
+ }
175
212
}
176
213
214
+
177
215
}
216
+
178
217
compileJava {
179
218
options. compilerArgs << ' -parameters'
180
219
}
0 commit comments