diff --git a/build.gradle b/build.gradle index 5cb5233..a07faae 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { if(System.getenv('TRAVIS')){ apply plugin: 'io.codearte.nexus-staging' - apply from : './scripts/deploy.gradle' + apply from: './scripts/deploy.gradle' } dependencies { diff --git a/scripts/deploy-jars.sh b/scripts/deploy-jars.sh new file mode 100644 index 0000000..7a115ec --- /dev/null +++ b/scripts/deploy-jars.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e # exit with nonzero exit code if anything fails + +openssl aes-256-cbc -K $encrypted_330589789bd4_key -iv $encrypted_330589789bd4_iv -in deployment.key.enc -out deployment.key -d +secreteFilePath=$(pwd)/deployment.key +echo "Deployment key found" + +echo "Executing gradle deployToMavenCentral" +./gradlew deployToMavenCentral -PdeploymentVersion=${TRAVIS_TAG} -Psigning.keyId=${signingKeyId} -Psigning.password=${signingPassword} -Psigning.secretKeyRingFile=$secreteFilePath -PossrhUsername=${ossrhUsername} -PossrhPassword=${ossrhPassword} --stacktrace --info + +rm $secreteFilePath \ No newline at end of file diff --git a/scripts/deploy.gradle b/scripts/deploy.gradle new file mode 100644 index 0000000..7c5b8ed --- /dev/null +++ b/scripts/deploy.gradle @@ -0,0 +1,99 @@ +/* + * Get the proper version for the project. This method will extract the version number from the project variable "deploymentVersion". +*/ +def getVersion = { + if( ! project.hasProperty('deploymentVersion') ) { + throw new RuntimeException("deploymentVersion not provided. You must specify a 'deploymentVersion' project variable (gradlew -PdeploymentVersion=..)") + } + + String tmpDeploymentVersion = deploymentVersion.replaceFirst("v", ""); + + if( ! tmpDeploymentVersion.matches("\\d+\\.\\d+\\.\\d+")) { + throw new RuntimeException("Version is not valid. Correct format is like 1.0.2 but was " + tmpDeploymentVersion) + } + + return tmpDeploymentVersion; +} + +/* + * Assert that the project properties necessary for the deployment to sonatype are correctly set. +*/ +def assertDeploymentPropertiesAreSet = { + boolean propertiesSet = project.getProperties().keySet().containsAll(Arrays.asList('ossrhUsername', 'ossrhPassword', 'signing.keyId', 'signing.password', 'signing.secretKeyRingFile')) + if( ! propertiesSet ) { + throw new RuntimeException("Deployment project properties are not correctly set: ossrhUsername, ossrhPassword, signing.keyId, signing.password, signing.secretKeyRingFile") + } +} + +signing { + required { gradle.getTaskGraph().hasTask("uploadArchives") } + sign configurations.archives +} + +task configureSonatypeDeployment(type: DefaultTask) << { + + assertDeploymentPropertiesAreSet() + + nexusStaging { + packageGroup = "org.tensorics" + username = ossrhUsername + password = ossrhPassword + // Sonatype Nexus may take some time to properly close the repo, it has to perform some checks + delayBetweenRetriesInMillis = 10000 + numberOfRetries = 10 + } + + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + pom.project { + name 'tensorics-expression' + packaging 'jar' + description '' + url 'http://www.tensorics.org' + + groupId 'org.tensorics' + artifactId 'tensorics-expression' + version getVersion() + + scm { + connection 'scm:git:https://github.com/tensorics/tensorics-expression.git' + developerConnection 'scm:git:https://github.com/tensorics/tensorics-expression.git' + url 'https://github.com/tensorics/tensorics-expression.git' + } + + licenses { + license { + name 'The Apache License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + + developers { + developer { + id 'andreacalia' + name 'Andrea Calia' + email 'andrea.calia.46@gmail.com' + } + } + + } + } + } + } +} + +// Define the deploying task and defining the order for the dependencies +task deployToMavenCentral(dependsOn: ['configureSonatypeDeployment', 'uploadArchives', 'closeAndPromoteRepository'], type: DefaultTask) +uploadArchives.mustRunAfter configureSonatypeDeployment +closeAndPromoteRepository.mustRunAfter uploadArchives