Skip to content

Commit

Permalink
[gradle] Reworking publishing pipeline
Browse files Browse the repository at this point in the history
TravisCI proxies separate external requests with different orginating IP
addresses, while Sonatype associates artifacts for auto-generated
repositories by IP address. This leads to many gradle deploys from CI
resulting in "split" staging repositories with no way to combine in
Sonatype Nexus.

This introduces a workflow which should resolve this issue on the next
revision release. Specifically, nexus-publish-plugin is included to
create singular staging repositories from TravisCI and
gradle-nexus-staging-plugin is included to auto-release and promote
this repository.

NOTE:
We need to publish via publishPluginMavenPublicationToNexusRepository,
because publishToNexus will publish _all_ publish-related tasks,
including the one intended only for the Gradle Plugin Portal.

Tested in standalone open source Nexus Repo Manager, which doesn't
support the staging plugin. So, only SNAPSHOT workflow has been
validated locally.
  • Loading branch information
jimschubert committed May 14, 2019
1 parent 3744273 commit ea12ed0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ after_success:
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";
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" publishPluginMavenPublicationToNexusRepository --no-daemon;
echo "Finished ./gradlew publishPluginMavenPublicationToNexusRepository";
popd;
elif ([[ "$TRAVIS_BRANCH" =~ ^[0-9]+\.[0-9]+\.x$ ]]) ; then
mvn clean deploy --settings CI/settings.xml;
Expand Down
135 changes: 56 additions & 79 deletions modules/openapi-generator-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.2.60'
ext.kotlin_version = '1.2.61'
repositories {
mavenCentral()
maven {
Expand All @@ -11,14 +11,13 @@ buildscript {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "gradle.plugin.org.gradle.kotlin:gradle-kotlin-dsl-plugins:1.0-rc-3"
classpath "com.gradle.publish:plugin-publish-plugin:0.10.1"
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.20.0"
classpath "de.marcphilipp.gradle:nexus-publish-plugin:0.2.0"
}
}

Expand All @@ -35,10 +34,11 @@ ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'java-gradle-plugin'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'kotlin'
apply plugin: "org.gradle.kotlin.kotlin-dsl"
apply plugin: 'io.codearte.nexus-staging'
apply plugin: "de.marcphilipp.nexus-publish"

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -87,6 +87,54 @@ test {
}
}


publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'OpenAPI-Generator Contributors'
description = project.description
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'
}
}
}
}
}

nexusPublishing {
username = ossrhUsername
password = ossrhPassword
stagingProfileId = "org.openapitools"
packageGroup = "org.openapitools"
}

gradlePlugin {
plugins {
openApiGenerator {
Expand All @@ -109,6 +157,7 @@ pluginBundle {
displayName = 'OpenAPI Generator Gradle Plugin'
tags = ['openapi-3.0', 'openapi-2.0', 'openapi', 'swagger', 'codegen', 'sdk']
version = "$openApiGeneratorVersion"
group = "org.openapitools"
}
}
}
Expand All @@ -119,79 +168,7 @@ pluginBundle {
// 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
}
}
}
sign publishing.publications
}

compileKotlin {
Expand All @@ -205,4 +182,4 @@ compileTestKotlin {
}
}

uploadArchives.dependsOn 'check'
publishToNexus.dependsOn 'check'
1 change: 1 addition & 0 deletions modules/openapi-generator-gradle-plugin/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
rootProject.name = 'openapi-generator-gradle-plugin'
enableFeaturePreview('STABLE_PUBLISHING')

0 comments on commit ea12ed0

Please sign in to comment.