Added option to sign archives for Gradle

This commit is contained in:
Marcin Grzejszczak
2016-09-23 19:44:00 +02:00
parent 3f6a1601ab
commit c37873f2b8
2 changed files with 47 additions and 4 deletions

View File

@@ -35,6 +35,7 @@ ext {
isReleaseVersion = version.endsWith("RELEASE")
isMilestoneVersion = version.matches('[0-9].[0-9].[0-9].M[0-9]+') || version.matches('[0-9].[0-9].[0-9].RC[0-9]+')
isSnapshotVersion = !(isReleaseVersion || isMilestoneVersion)
isReleaseToCentral = project.hasProperty('central')
resolveVersion = { String version ->
if (isMilestoneVersion) return 'milestone'
@@ -42,7 +43,15 @@ ext {
return 'snapshot'
}
repoUrl = "https://repo.spring.io/${resolveRepoName(project)}"
repoUrl = isReleaseToCentral ?
"https://oss.sonatype.org/service/local/staging/deploy/maven2/" :
"https://repo.spring.io/${resolveRepoName(project)}"
}
if (isReleaseToCentral) {
signing {
sign configurations.archives
}
}
afterEvaluate {
@@ -50,17 +59,19 @@ afterEvaluate {
repositories {
mavenDeployer {
// POM signature
if (isReleaseVersion) {
if (isReleaseVersion && isReleaseToCentral) {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
}
// Target repository
String repoUserName = isReleaseToCentral ? sonatypeUsername : repoUser
String repoPass = isReleaseToCentral ? sonatypePassword : repoPass
repository(url: repoUrl) {
authentication(userName: repoUser, password: repoPass)
authentication(userName: repoUserName, password: repoPass)
}
pom.project {
name "$project.name"
packaging 'jar'
description 'Spring Cloud Contract'
description 'Spring Cloud Contract Gradle Plugin'
url 'https://github.com/spring-cloud/spring-cloud-contract'
inceptionYear '2014'

View File

@@ -155,6 +155,38 @@
</plugins>
</build>
</profile>
<profile>
<id>central</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>gradle</id>
<phase>package</phase>
<configuration>
<executable>./gradlew</executable>
<arguments>
<argument>clean</argument>
<argument>build</argument>
<argument>sign</argument>
<argument>-Pcentral</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>