|
1 | 1 | plugins {
|
2 | 2 | // code formatting
|
3 | 3 | id "com.diffplug.gradle.spotless" version "1.2.0"
|
| 4 | + // bintray upload |
| 5 | + id "com.jfrog.bintray" version "1.3.1" |
4 | 6 | }
|
5 | 7 |
|
6 | 8 | repositories {
|
7 | 9 | mavenCentral()
|
8 | 10 | // SNAPSHOT versions are free to rely on other SNAPSHOT libraries
|
9 | 11 | if (project.version.endsWith('-SNAPSHOT')) {
|
10 |
| - maven { |
11 |
| - url 'https://oss.sonatype.org/content/repositories/snapshots/' |
12 |
| - } |
13 |
| - configurations.all { |
14 |
| - resolutionStrategy.cacheChangingModulesFor 0, 'seconds' |
15 |
| - } |
| 12 | + maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } |
| 13 | + configurations.all { resolutionStrategy.cacheChangingModulesFor 0, 'seconds' } |
16 | 14 | }
|
17 | 15 | }
|
18 | 16 |
|
@@ -121,6 +119,21 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
|
121 | 119 | from javadoc.destinationDir
|
122 | 120 | }
|
123 | 121 |
|
| 122 | +//////////////// |
| 123 | +// PUBLISHING // |
| 124 | +//////////////// |
| 125 | +def isSnapshot = project.version.endsWith('-SNAPSHOT') |
| 126 | +// pulls the credentials from either the environment variable or gradle.properties |
| 127 | +def cred = { |
| 128 | + if (System.env[it] != null) { |
| 129 | + return System.env[it] |
| 130 | + } else if (project[it] != null) { |
| 131 | + return project[it] |
| 132 | + } else { |
| 133 | + return 'unknown_' + it |
| 134 | + } |
| 135 | +} |
| 136 | + |
124 | 137 | publishing {
|
125 | 138 | publications {
|
126 | 139 | mavenJava(MavenPublication) {
|
@@ -159,20 +172,41 @@ publishing {
|
159 | 172 | }
|
160 | 173 | }
|
161 | 174 | }
|
162 |
| - repositories { |
163 |
| - maven { |
164 |
| - def isSnapshot = project.version.endsWith('-SNAPSHOT') |
165 |
| - if (isSnapshot) { |
166 |
| - url = 'https://oss.sonatype.org/content/repositories/snapshots' |
167 |
| - } else { |
168 |
| - url = "https://api.bintray.com/maven/diffplug/opensource/${project.name}" |
169 |
| - } |
| 175 | + if (isSnapshot) { |
| 176 | + // upload snapshots to oss.sonatype.org |
| 177 | + repositories { maven { |
| 178 | + url = 'https://oss.sonatype.org/content/repositories/snapshots' |
170 | 179 | credentials {
|
171 |
| - username = System.env[isSnapshot ? 'nexus_user' : 'bintray_user'] |
172 |
| - password = System.env[isSnapshot ? 'nexus_pass' : 'bintray_pass'] |
| 180 | + username = cred('nexus_user') |
| 181 | + password = cred('nexus_pass') |
| 182 | + } |
| 183 | + } } |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | +if (!isSnapshot) { |
| 188 | + // upload releases to bintray and then mavenCentral |
| 189 | + bintray { |
| 190 | + user = cred('bintray_user') |
| 191 | + key = cred('bintray_pass') |
| 192 | + publications = ['mavenJava'] |
| 193 | + publish = true |
| 194 | + pkg { |
| 195 | + repo = 'opensource' |
| 196 | + name = project.name |
| 197 | + userOrg = project.org |
| 198 | + version { |
| 199 | + name = project.version |
| 200 | + mavenCentralSync { |
| 201 | + user = cred('nexus_user') |
| 202 | + password = cred('nexus_pass') |
| 203 | + } |
173 | 204 | }
|
174 | 205 | }
|
175 | 206 | }
|
| 207 | + |
| 208 | + publish.dependsOn(bintrayUpload) |
| 209 | + bintrayUpload.dependsOn(['generatePomFileForMavenJavaPublication', jar, sourcesJar, javadocJar]) |
176 | 210 | }
|
177 | 211 |
|
178 | 212 | // helps external scripts detect version
|
|
0 commit comments