[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
This commit is contained in:
Jim Schubert 2018-06-09 14:21:31 -04:00 committed by GitHub
parent f72059e7ac
commit 5a332f3c57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 173 additions and 11 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
out/
*.ipr
*.iws
*.gpg
classpath.txt
version.properties
!modules/openapi-generator-cli/src/main/resources/version.properties

View File

@ -9,8 +9,9 @@ cache:
- $HOME/.ivy2
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/samples/client/petstore/javascript/node_modules
- $HOME/samples/client/petstore/php/OpenAPIToolsClient-php/vendor
- $HOME/samples/client/petstore/ruby/venodr/bundle
- $HOME/samples/client/petstore/ruby/vendor/bundle
- $HOME/samples/client/petstore/python/.venv/
- $HOME/samples/client/petstore/typescript-node/npm/node_modules
- $HOME/samples/client/petstore/typescript-node/npm/typings/
@ -26,6 +27,10 @@ cache:
- $HOME/samples/client/petstore/typescript-angular/typings
- $HOME/perl5
# Don't cache artifacts installed by this build.
before_cache:
- rm -rf $HOME/.m2/repository/org/openapitools
services:
- docker
@ -72,6 +77,8 @@ before_install:
- cat /etc/hosts
# show java version
- java -version
- openssl aes-256-cbc -K $encrypted_6e2c8bba47c6_key -iv $encrypted_6e2c8bba47c6_iv -in sec.gpg.enc -out sec.gpg -d
- gpg --keyserver pgp.mit.edu --recv-key $SIGNING_KEY
install:
# Add Godeps dependencies to GOPATH and PATH
@ -93,10 +100,15 @@ script:
- mvn --quiet clean install
- mvn --quiet verify -Psamples
after_success:
# push a snapshot version to maven repo
- if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ]; then
mvn clean deploy --settings CI/settings.xml;
# push to maven repo
- if [ $SONATYPE_USERNAME ] && [ -z $TRAVIS_TAG ] && [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
mvn clean deploy -DskipTests=true -B -U -P release --settings CI/settings.xml;
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
pushd .
cd modules/openapi-generator-gradle-plugin
./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
echo "Finished ./gradlew uploadArchives"
popd
fi;
## docker: build and push openapi-generator-online to DockerHub
- 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

View File

@ -13,6 +13,18 @@
</servers>
<mirrors/>
<proxies/>
<profiles/>
<profiles>
<profile>
<id>release</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.keyname>${env.SIGNING_KEY}</gpg.keyname>
<gpg.passphrase>${env.SIGNING_PASSPHRASE}</gpg.passphrase>
</properties>
</profile>
</profiles>
<activeProfiles/>
</settings>

View File

@ -21,9 +21,11 @@ This plugin supports common functionality found in Open API Generator CLI as a g
This gives you the ability to generate client SDKs, documentation, new generators, and to validate Open API 2.0 and 3.x
specifications as part of your build. Other tasks are available as command line tasks.
"""
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
apply plugin: 'java-gradle-plugin'
apply plugin: 'maven-publish'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'kotlin'
apply plugin: "org.gradle.kotlin.kotlin-dsl"
@ -67,7 +69,6 @@ test {
}
}
gradlePlugin {
plugins {
openApiGenerator {
@ -77,6 +78,87 @@ gradlePlugin {
}
}
// signing will require three keys to be defined: signing.keyId, signing.password, and signing.secretKeyRingFile.
// These can be passed to the gradle command:
// ./gradlew -Psigning.keyId=yourid
// or stored as key=value pairs in ~/.gradle/gradle.properties
// You can also apply them in CI via environment variables. See Gradle's docs for details.
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
artifacts {
archives javadocJar, sourcesJar
}
def pomConfig = {
description project.description
name 'OpenAPI-Generator Contributors'
url 'https://openapi-generator.tech'
organization {
name 'org.openapitools'
url 'https://github.com/OpenAPITools'
}
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
developers {
developer {
id "openapitools"
name "OpenAPI-Generator Contributors"
email "team@openapitools.org"
}
}
scm {
url 'https://github.com/OpenAPITools/openapi-generator'
connection 'scm:git:git://github.com/OpenAPITools/openapi-generator.git'
developerConnection 'scm:git:ssh://git@github.com:OpenAPITools/openapi-generator.git'
}
issueManagement {
system 'GitHub'
url 'https://github.com/OpenAPITools/openapi-generator/issues'
}
}
uploadArchives {
repositories {
// credentials here would need to be passed along with the gradle command:
// ./gradlew -P ossrhUsername=yourUser
// or stored in ~/.gradle/gradle.properties as key=value pairs
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.withXml {
def root = asNode()
root.appendNode('description', project.description)
root.children().last() + pomConfig
}
}
}
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
@ -86,4 +168,4 @@ compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
}

View File

@ -1 +1,10 @@
openApiGeneratorVersion=3.0.1-SNAPSHOT
# BEGIN placeholders
# these are just placeholders to allow contributors to build directly
ossrhUsername=user
ossrhPassword=pass
signing.keyId=unset
signing.password=unset
# signing.secretKeyRingFile=unset
# END placeholders

View File

@ -56,10 +56,10 @@
</goals>
<configuration>
<tasks>
<!-- calls "clean build publishToMavenLocal" -->
<!-- calls "clean assemble install" -->
<task>clean</task>
<task>build</task>
<task>publishToMavenLocal</task>
<task>assemble</task>
<task>install</task>
</tasks>
</configuration>
</execution>

View File

@ -5,6 +5,12 @@ buildscript {
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "https://oss.sonatype.org/content/repositories/releases/"
}
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath "org.openapitools:openapi-generator-gradle-plugin:3.0.0-SNAPSHOT"

40
pom.xml
View File

@ -60,6 +60,12 @@
<system>github</system>
<url>https://github.com/openapitools/openapi-generator/issues</url>
</issueManagement>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<licenses>
<license>
<name>Apache License 2.0</name>
@ -279,6 +285,40 @@
</pluginManagement>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release-profile</id>
<properties>

BIN
sec.gpg.enc Normal file

Binary file not shown.