@@ -113,13 +113,18 @@ subprojects {
113
113
publishing {
114
114
repositories {
115
115
maven {
116
+ // Snapshot uses a different repository than release.
117
+ // The publish in that case will upload to Maven Central snapshot repository.
116
118
if (version. endsWith(' SNAPSHOT' )) {
117
119
url = ' https://central.sonatype.com/repository/maven-snapshots/'
118
120
credentials {
119
121
username = System . getenv(" MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME" )
120
122
password = System . getenv(" MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD" )
121
123
}
122
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.
123
128
url = " ${ buildDir} /local-repo"
124
129
}
125
130
}
@@ -167,6 +172,10 @@ subprojects {
167
172
168
173
169
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.
170
179
if (! version. toString(). endsWith(' SNAPSHOT' )) {
171
180
dependsOn tasks. publish
172
181
}
@@ -186,6 +195,10 @@ subprojects {
186
195
}
187
196
188
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.
189
202
if (version. toString(). endsWith(' SNAPSHOT' )) {
190
203
dependsOn tasks. publish
191
204
}
0 commit comments