Skip to content

Commit 5a332f3

Browse files
authored
[gradle] Plugin release management (#201)
* [gradle] Plugin release management This applies steps necessary for publishing to Sonatype, including sources, javadoc, jar and signing. Also includes full POM details, per Sonatype requirements. * Properties placeholders in gradle plugin (should allow users without these settings to build locally) * Update build wrapper for install task to be used with new maven plugin, not maven-publish plugin * Add code signing for gradle and maven
1 parent f72059e commit 5a332f3

9 files changed

Lines changed: 173 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
out/
44
*.ipr
55
*.iws
6+
*.gpg
67
classpath.txt
78
version.properties
89
!modules/openapi-generator-cli/src/main/resources/version.properties

.travis.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ cache:
99
- $HOME/.ivy2
1010
- $HOME/.gradle/caches/
1111
- $HOME/.gradle/wrapper/
12+
- $HOME/samples/client/petstore/javascript/node_modules
1213
- $HOME/samples/client/petstore/php/OpenAPIToolsClient-php/vendor
13-
- $HOME/samples/client/petstore/ruby/venodr/bundle
14+
- $HOME/samples/client/petstore/ruby/vendor/bundle
1415
- $HOME/samples/client/petstore/python/.venv/
1516
- $HOME/samples/client/petstore/typescript-node/npm/node_modules
1617
- $HOME/samples/client/petstore/typescript-node/npm/typings/
@@ -26,6 +27,10 @@ cache:
2627
- $HOME/samples/client/petstore/typescript-angular/typings
2728
- $HOME/perl5
2829

30+
# Don't cache artifacts installed by this build.
31+
before_cache:
32+
- rm -rf $HOME/.m2/repository/org/openapitools
33+
2934
services:
3035
- docker
3136

@@ -72,6 +77,8 @@ before_install:
7277
- cat /etc/hosts
7378
# show java version
7479
- java -version
80+
- openssl aes-256-cbc -K $encrypted_6e2c8bba47c6_key -iv $encrypted_6e2c8bba47c6_iv -in sec.gpg.enc -out sec.gpg -d
81+
- gpg --keyserver pgp.mit.edu --recv-key $SIGNING_KEY
7582

7683
install:
7784
# Add Godeps dependencies to GOPATH and PATH
@@ -93,10 +100,15 @@ script:
93100
- mvn --quiet clean install
94101
- mvn --quiet verify -Psamples
95102
after_success:
96-
# push a snapshot version to maven repo
97-
- if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ]; then
98-
mvn clean deploy --settings CI/settings.xml;
103+
# push to maven repo
104+
- if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
105+
mvn clean deploy -DskipTests=true -B -U -P release --settings CI/settings.xml;
99106
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
107+
pushd .
108+
cd modules/openapi-generator-gradle-plugin
109+
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon
110+
echo "Finished ./gradlew uploadArchives"
111+
popd
100112
fi;
101113
## docker: build and push openapi-generator-online to DockerHub
102114
- if [ $DOCKER_HUB_USERNAME ]; then echo "$DOCKER_HUB_PASSWORD" | docker login --username=$DOCKER_HUB_USERNAME --password-stdin && docker build -t $DOCKER_GENERATOR_IMAGE_NAME ./modules/openapi-generator-online && if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_GENERATOR_IMAGE_NAME:latest $DOCKER_GENERATOR_IMAGE_NAME:$TRAVIS_TAG; fi && if [ ! -z "$TRAVIS_TAG" ] || [ "$TRAVIS_BRANCH" = "master" ]; then docker push $DOCKER_GENERATOR_IMAGE_NAME && echo "Pushed to $DOCKER_GENERATOR_IMAGE_NAME"; fi; fi

CI/settings.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
</servers>
1414
<mirrors/>
1515
<proxies/>
16-
<profiles/>
16+
<profiles>
17+
<profile>
18+
<id>release</id>
19+
<activation>
20+
<activeByDefault>true</activeByDefault>
21+
</activation>
22+
<properties>
23+
<gpg.executable>gpg</gpg.executable>
24+
<gpg.keyname>${env.SIGNING_KEY}</gpg.keyname>
25+
<gpg.passphrase>${env.SIGNING_PASSPHRASE}</gpg.passphrase>
26+
</properties>
27+
</profile>
28+
</profiles>
1729
<activeProfiles/>
1830
</settings>

modules/openapi-generator-gradle-plugin/build.gradle

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ This plugin supports common functionality found in Open API Generator CLI as a g
2121
This gives you the ability to generate client SDKs, documentation, new generators, and to validate Open API 2.0 and 3.x
2222
specifications as part of your build. Other tasks are available as command line tasks.
2323
"""
24+
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
2425

2526
apply plugin: 'java-gradle-plugin'
26-
apply plugin: 'maven-publish'
27+
apply plugin: 'maven'
28+
apply plugin: 'signing'
2729
apply plugin: 'kotlin'
2830
apply plugin: "org.gradle.kotlin.kotlin-dsl"
2931

@@ -67,7 +69,6 @@ test {
6769
}
6870
}
6971

70-
7172
gradlePlugin {
7273
plugins {
7374
openApiGenerator {
@@ -77,6 +78,87 @@ gradlePlugin {
7778
}
7879
}
7980

81+
// signing will require three keys to be defined: signing.keyId, signing.password, and signing.secretKeyRingFile.
82+
// These can be passed to the gradle command:
83+
// ./gradlew -Psigning.keyId=yourid
84+
// or stored as key=value pairs in ~/.gradle/gradle.properties
85+
// You can also apply them in CI via environment variables. See Gradle's docs for details.
86+
signing {
87+
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
88+
sign configurations.archives
89+
}
90+
91+
task javadocJar(type: Jar) {
92+
classifier = 'javadoc'
93+
from javadoc
94+
}
95+
96+
task sourcesJar(type: Jar) {
97+
from sourceSets.main.allSource
98+
classifier = 'sources'
99+
}
100+
101+
artifacts {
102+
archives javadocJar, sourcesJar
103+
}
104+
105+
def pomConfig = {
106+
description project.description
107+
name 'OpenAPI-Generator Contributors'
108+
url 'https://openapi-generator.tech'
109+
organization {
110+
name 'org.openapitools'
111+
url 'https://github.com/OpenAPITools'
112+
}
113+
licenses {
114+
license {
115+
name "The Apache Software License, Version 2.0"
116+
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
117+
distribution "repo"
118+
}
119+
}
120+
developers {
121+
developer {
122+
id "openapitools"
123+
name "OpenAPI-Generator Contributors"
124+
email "team@openapitools.org"
125+
}
126+
}
127+
scm {
128+
url 'https://github.com/OpenAPITools/openapi-generator'
129+
connection 'scm:git:git://github.com/OpenAPITools/openapi-generator.git'
130+
developerConnection 'scm:git:ssh://git@github.com:OpenAPITools/openapi-generator.git'
131+
}
132+
issueManagement {
133+
system 'GitHub'
134+
url 'https://github.com/OpenAPITools/openapi-generator/issues'
135+
}
136+
}
137+
138+
uploadArchives {
139+
repositories {
140+
141+
// credentials here would need to be passed along with the gradle command:
142+
// ./gradlew -P ossrhUsername=yourUser
143+
// or stored in ~/.gradle/gradle.properties as key=value pairs
144+
mavenDeployer {
145+
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
146+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
147+
authentication(userName: ossrhUsername, password: ossrhPassword)
148+
}
149+
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
150+
authentication(userName: ossrhUsername, password: ossrhPassword)
151+
}
152+
153+
pom.withXml {
154+
def root = asNode()
155+
root.appendNode('description', project.description)
156+
root.children().last() + pomConfig
157+
}
158+
}
159+
}
160+
}
161+
80162
compileKotlin {
81163
kotlinOptions {
82164
jvmTarget = "1.8"
@@ -86,4 +168,4 @@ compileTestKotlin {
86168
kotlinOptions {
87169
jvmTarget = "1.8"
88170
}
89-
}
171+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
openApiGeneratorVersion=3.0.1-SNAPSHOT
2+
3+
# BEGIN placeholders
4+
# these are just placeholders to allow contributors to build directly
5+
ossrhUsername=user
6+
ossrhPassword=pass
7+
signing.keyId=unset
8+
signing.password=unset
9+
# signing.secretKeyRingFile=unset
10+
# END placeholders

modules/openapi-generator-gradle-plugin/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
</goals>
5757
<configuration>
5858
<tasks>
59-
<!-- calls "clean build publishToMavenLocal" -->
59+
<!-- calls "clean assemble install" -->
6060
<task>clean</task>
61-
<task>build</task>
62-
<task>publishToMavenLocal</task>
61+
<task>assemble</task>
62+
<task>install</task>
6363
</tasks>
6464
</configuration>
6565
</execution>

modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ buildscript {
55
maven {
66
url "https://plugins.gradle.org/m2/"
77
}
8+
maven {
9+
url "https://oss.sonatype.org/content/repositories/releases/"
10+
}
11+
maven {
12+
url "https://oss.sonatype.org/content/repositories/snapshots/"
13+
}
814
}
915
dependencies {
1016
classpath "org.openapitools:openapi-generator-gradle-plugin:3.0.0-SNAPSHOT"

pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060
<system>github</system>
6161
<url>https://github.com/openapitools/openapi-generator/issues</url>
6262
</issueManagement>
63+
<distributionManagement>
64+
<snapshotRepository>
65+
<id>ossrh</id>
66+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
67+
</snapshotRepository>
68+
</distributionManagement>
6369
<licenses>
6470
<license>
6571
<name>Apache License 2.0</name>
@@ -279,6 +285,40 @@
279285
</pluginManagement>
280286
</build>
281287
<profiles>
288+
289+
<profile>
290+
<id>release</id>
291+
<build>
292+
<plugins>
293+
<plugin>
294+
<groupId>org.apache.maven.plugins</groupId>
295+
<artifactId>maven-gpg-plugin</artifactId>
296+
<version>1.6</version>
297+
<executions>
298+
<execution>
299+
<id>sign-artifacts</id>
300+
<phase>verify</phase>
301+
<goals>
302+
<goal>sign</goal>
303+
</goals>
304+
</execution>
305+
</executions>
306+
</plugin>
307+
<plugin>
308+
<groupId>org.sonatype.plugins</groupId>
309+
<artifactId>nexus-staging-maven-plugin</artifactId>
310+
<version>1.6.8</version>
311+
<extensions>true</extensions>
312+
<configuration>
313+
<serverId>ossrh</serverId>
314+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
315+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
316+
</configuration>
317+
</plugin>
318+
</plugins>
319+
</build>
320+
</profile>
321+
282322
<profile>
283323
<id>release-profile</id>
284324
<properties>

sec.gpg.enc

5.53 KB
Binary file not shown.

0 commit comments

Comments
 (0)