|
| 1 | +/* |
| 2 | + * Get the proper version for the project. This method will extract the version number from the project variable "deploymentVersion". |
| 3 | +*/ |
| 4 | +def getVersion = { |
| 5 | + if( ! project.hasProperty('deploymentVersion') ) { |
| 6 | + throw new RuntimeException("deploymentVersion not provided. You must specify a 'deploymentVersion' project variable (gradlew -PdeploymentVersion=..)") |
| 7 | + } |
| 8 | + |
| 9 | + String tmpDeploymentVersion = deploymentVersion.replaceFirst("v", ""); |
| 10 | + |
| 11 | + if( ! tmpDeploymentVersion.matches("\\d+\\.\\d+\\.\\d+")) { |
| 12 | + throw new RuntimeException("Version is not valid. Correct format is like 1.0.2 but was " + tmpDeploymentVersion) |
| 13 | + } |
| 14 | + |
| 15 | + return tmpDeploymentVersion; |
| 16 | +} |
| 17 | + |
| 18 | +/* |
| 19 | + * Assert that the project properties necessary for the deployment to sonatype are correctly set. |
| 20 | +*/ |
| 21 | +def assertDeploymentPropertiesAreSet = { |
| 22 | + boolean propertiesSet = project.getProperties().keySet().containsAll(Arrays.asList('ossrhUsername', 'ossrhPassword', 'signing.keyId', 'signing.password', 'signing.secretKeyRingFile')) |
| 23 | + if( ! propertiesSet ) { |
| 24 | + throw new RuntimeException("Deployment project properties are not correctly set: ossrhUsername, ossrhPassword, signing.keyId, signing.password, signing.secretKeyRingFile") |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +signing { |
| 29 | + required { gradle.getTaskGraph().hasTask("uploadArchives") } |
| 30 | + sign configurations.archives |
| 31 | +} |
| 32 | + |
| 33 | +task configureSonatypeDeployment(type: DefaultTask) << { |
| 34 | + |
| 35 | + assertDeploymentPropertiesAreSet() |
| 36 | + |
| 37 | + nexusStaging { |
| 38 | + packageGroup = "org.tensorics" |
| 39 | + username = ossrhUsername |
| 40 | + password = ossrhPassword |
| 41 | + // Sonatype Nexus may take some time to properly close the repo, it has to perform some checks |
| 42 | + delayBetweenRetriesInMillis = 10000 |
| 43 | + numberOfRetries = 10 |
| 44 | + } |
| 45 | + |
| 46 | + uploadArchives { |
| 47 | + repositories { |
| 48 | + mavenDeployer { |
| 49 | + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } |
| 50 | + |
| 51 | + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { |
| 52 | + authentication(userName: ossrhUsername, password: ossrhPassword) |
| 53 | + } |
| 54 | + |
| 55 | + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { |
| 56 | + authentication(userName: ossrhUsername, password: ossrhPassword) |
| 57 | + } |
| 58 | + |
| 59 | + pom.project { |
| 60 | + name 'tensorics-expression' |
| 61 | + packaging 'jar' |
| 62 | + description '' |
| 63 | + url 'http://www.tensorics.org' |
| 64 | + |
| 65 | + groupId 'org.tensorics' |
| 66 | + artifactId 'tensorics-expression' |
| 67 | + version getVersion() |
| 68 | + |
| 69 | + scm { |
| 70 | + connection 'scm:git:https://github.com/tensorics/tensorics-expression.git' |
| 71 | + developerConnection 'scm:git:https://github.com/tensorics/tensorics-expression.git' |
| 72 | + url 'https://github.com/tensorics/tensorics-expression.git' |
| 73 | + } |
| 74 | + |
| 75 | + licenses { |
| 76 | + license { |
| 77 | + name 'The Apache License, Version 2.0' |
| 78 | + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + developers { |
| 83 | + developer { |
| 84 | + id 'andreacalia' |
| 85 | + name 'Andrea Calia' |
| 86 | + |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +// Define the deploying task and defining the order for the dependencies |
| 97 | +task deployToMavenCentral(dependsOn: ['configureSonatypeDeployment', 'uploadArchives', 'closeAndPromoteRepository'], type: DefaultTask) |
| 98 | +uploadArchives.mustRunAfter configureSonatypeDeployment |
| 99 | +closeAndPromoteRepository.mustRunAfter uploadArchives |
0 commit comments