|
2 | 2 | // License https://www.backblaze.com/using_b2_code.html |
3 | 3 |
|
4 | 4 | import org.gradle.api.credentials.PasswordCredentials |
| 5 | +import org.gradle.api.publish.internal.PublicationInternal |
5 | 6 |
|
6 | 7 | plugins { |
7 | 8 | java |
| 9 | + signing |
8 | 10 | `maven-publish` |
9 | 11 | } |
10 | 12 |
|
@@ -87,9 +89,13 @@ publishing { |
87 | 89 | groupId = project.group.toString() |
88 | 90 | artifactId = project.name |
89 | 91 |
|
90 | | - version = when (val buildNum = providers.environmentVariable("BUILD_NUMBER").forUseAtConfigurationTime().orNull) { |
91 | | - null -> project.version.toString() |
92 | | - else -> "${project.version}+$buildNum" |
| 92 | + if (System.getenv("RELEASE_BUILD") != null) { |
| 93 | + version = project.version.toString() |
| 94 | + } else { |
| 95 | + version = when (val buildNum = System.getenv("BUILD_NUMBER")) { |
| 96 | + null -> project.version.toString() |
| 97 | + else -> "${project.version}+$buildNum" |
| 98 | + } |
93 | 99 | } |
94 | 100 |
|
95 | 101 | withoutBuildIdentifier() |
@@ -133,3 +139,34 @@ publishing { |
133 | 139 | } |
134 | 140 | } |
135 | 141 | } |
| 142 | + |
| 143 | +val sonatypeUsername = findProperty("sonatypeUsername") |
| 144 | +val sonatypePassword = findProperty("sonatypePassword") |
| 145 | + |
| 146 | +val gpgSigningKey = System.getenv("GPG_SIGNING_KEY") |
| 147 | +val gpgPassphrase = System.getenv("GPG_PASSPHRASE") |
| 148 | + |
| 149 | +signing { |
| 150 | + setRequired { |
| 151 | + gradle.taskGraph.hasTask("publishToSonatype") || gradle.taskGraph.hasTask("createBundle") |
| 152 | + } |
| 153 | + |
| 154 | + if (gpgSigningKey != null && gpgPassphrase != null) { |
| 155 | + useInMemoryPgpKeys(gpgSigningKey, gpgPassphrase) |
| 156 | + } else { |
| 157 | + useGpgCmd() |
| 158 | + } |
| 159 | + |
| 160 | + sign(publishing.publications["maven"]) |
| 161 | +} |
| 162 | + |
| 163 | +tasks.register<Jar>("createBundle") { |
| 164 | + archiveBaseName.set("bundle-for-${project.name}") |
| 165 | + from((project.publishing.publications["maven"] as PublicationInternal<*>).publishableArtifacts.files) { |
| 166 | + rename { |
| 167 | + it |
| 168 | + .replace("pom-default.xml", "${project.name}-${project.version}.pom") |
| 169 | + .replace("module.json", "${project.name}-${project.version}.module") |
| 170 | + } |
| 171 | + } |
| 172 | +} |
0 commit comments