-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gradle] Reworking publishing pipeline (#2886)
* [gradle] Reworking publishing pipeline 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. * Change the 'publish' task to 'publishToMavenLocal' in the helper pom.xml * Add condition on signing and be explicit about sources/javadoc artifacts * Call close/closeAndReleaseRepository * Reuse same closeAndReleaseRepository for SNAPSHOT + releases using a task guard, and publish to Gradle Plugin portal only on tagged build. * Add v prefix for tag check.
- Loading branch information
1 parent
c509d98
commit 6a1fc51
Showing
4 changed files
with
100 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
@@ -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" | ||
} | ||
} | ||
|
||
|
@@ -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 | ||
|
@@ -87,6 +87,65 @@ test { | |
} | ||
} | ||
|
||
task javadocJar(type: Jar) { | ||
from javadoc | ||
classifier = 'javadoc' | ||
} | ||
|
||
task sourcesJar(type: Jar) { | ||
from sourceSets.main.allSource | ||
classifier = 'sources' | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
from components.java | ||
artifact sourcesJar | ||
artifact javadocJar | ||
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 = "[email protected]" | ||
} | ||
} | ||
scm { | ||
url = 'https://github.com/OpenAPITools/openapi-generator' | ||
connection = 'scm:git:git://github.com/OpenAPITools/openapi-generator.git' | ||
developerConnection = 'scm:git:ssh://[email protected]: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 { | ||
|
@@ -109,6 +168,7 @@ pluginBundle { | |
displayName = 'OpenAPI Generator Gradle Plugin' | ||
tags = ['openapi-3.0', 'openapi-2.0', 'openapi', 'swagger', 'codegen', 'sdk'] | ||
version = "$openApiGeneratorVersion" | ||
group = "org.openapitools" | ||
} | ||
} | ||
} | ||
|
@@ -119,79 +179,8 @@ 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 "[email protected]" | ||
} | ||
} | ||
scm { | ||
url 'https://github.com/OpenAPITools/openapi-generator' | ||
connection 'scm:git:git://github.com/OpenAPITools/openapi-generator.git' | ||
developerConnection 'scm:git:ssh://[email protected]: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 | ||
} | ||
} | ||
} | ||
required { isReleaseVersion && (gradle.taskGraph.hasTask("publishPluginMavenPublicationToNexusRepository") ) } | ||
sign publishing.publications.mavenJava | ||
} | ||
|
||
compileKotlin { | ||
|
@@ -205,4 +194,19 @@ compileTestKotlin { | |
} | ||
} | ||
|
||
uploadArchives.dependsOn 'check' | ||
javadoc { | ||
if(JavaVersion.current().isJava9Compatible()) { | ||
options.addBooleanOption('html5', true) | ||
} | ||
} | ||
|
||
tasks { | ||
closeRepository { | ||
onlyIf { nexusPublishing.useStaging.get() } | ||
} | ||
releaseRepository{ | ||
onlyIf { nexusPublishing.useStaging.get() } | ||
} | ||
} | ||
|
||
publishToNexus.dependsOn 'check' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
rootProject.name = 'openapi-generator-gradle-plugin' | ||
enableFeaturePreview('STABLE_PUBLISHING') | ||
|