Skip to content

Use Gradle 7.6 to build Gradle plugin #13860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ 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}" publishMavenJavaPublicationToNexusRepository closeAndReleaseRepository --no-daemon;
echo "Finished ./gradlew publishPluginMavenPublicationToNexusRepository closeAndReleaseRepository";
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" publishPluginMavenPublicationToSonatypeRepository closeAndReleaseRepository;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not figure out why previously the publishMavenJavaPublicationToNexusRepository task was called in the first if condition, but the publishPluginMavenPublicationToNexusRepository task was called in the second. I came to the conclusion this was probably not intentional.

In any case, there is no longer a mavenJava publication so publishPluginMavenPublicationToSonatypeRepository is called in both places.

echo "Finished ./gradlew publishPluginMavenPublicationToSonatypeRepository closeAndReleaseRepository";
popd;
elif [ -z $TRAVIS_TAG ] && [[ "$TRAVIS_BRANCH" =~ ^[0-9]+\.[0-9]+\.x$ ]]; then
echo "Publishing from branch $TRAVIS_BRANCH";
mvn clean deploy --settings CI/settings.xml;
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
pushd .;
cd modules/openapi-generator-gradle-plugin;
./gradlew -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" publishPluginMavenPublicationToNexusRepository closeAndReleaseRepository --no-daemon;
echo "Finished ./gradlew publishPluginMavenPublicationToNexusRepository closeAndReleaseRepository";
./gradlew -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" publishPluginMavenPublicationToSonatypeRepository closeAndReleaseRepository;
echo "Finished ./gradlew publishPluginMavenPublicationToSonatypeRepository closeAndReleaseRepository";
popd;
fi;
if [ -n $TRAVIS_TAG ] && [[ "$TRAVIS_TAG" =~ ^[v][0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Publishing the gradle plugin to Gradle Portal on tag $TRAVIS_TAG (only)";
pushd .;
cd modules/openapi-generator-gradle-plugin;
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" publishPlugins -Dgradle.publish.key=$GRADLE_PUBLISH_KEY -Dgradle.publish.secret=$GRADLE_PUBLISH_SECRET --no-daemon;
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" publishPlugins -Dgradle.publish.key=$GRADLE_PUBLISH_KEY -Dgradle.publish.secret=$GRADLE_PUBLISH_SECRET;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erichaagdev we're working on v6.3.0 release but Travis CI shows the following errors:

For more details see https://docs.gradle.org/7.6/release-notes.html


> Configure project :
Signing plugin detected. Will automatically sign the published artifacts.

> Task :pluginDescriptors UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :sourcesJar UP-TO-DATE
> Task :generatePomFileForPluginMavenPublication
> Task :generatePomFileForOpenApiGeneratorPluginMarkerMavenPublication
> Task :signOpenApiGeneratorPluginMarkerMavenPublication FAILED

> Task :compileKotlin
w: /home/travis/build/OpenAPITools/openapi-generator/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt: (805, 48): 'getter for config: CodegenConfig!' is deprecated. Deprecated in Java
w: /home/travis/build/OpenAPITools/openapi-generator/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt: (811, 40): 'getter for config: CodegenConfig!' is deprecated. Deprecated in Java

FAILURE: Build failed with an exception.

* What went wrong:
Could not evaluate onlyIf predicate for task ':signOpenApiGeneratorPluginMarkerMavenPublication'.
> Could not evaluate spec for 'Signing is required, or signatory is set'.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.6/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 9s
7 actionable tasks: 4 executed, 3 up-to-date

Do you know what may have caused this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo "Finished ./gradlew publishPlugins (plugin portal)";
popd;
fi;
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ install:
# install gradle
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\gradle\gradle-5.6.4" )) {
if (!(Test-Path -Path "C:\gradle\gradle-7.6" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://services.gradle.org/distributions/gradle-5.6.4-bin.zip',
'https://services.gradle.org/distributions/gradle-7.6-bin.zip',
'C:\gradle-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\gradle-bin.zip", "C:\gradle")
}
- cmd: SET PATH=C:\maven\apache-maven-3.8.3\bin;C:\gradle\gradle-5.6.4\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET PATH=C:\maven\apache-maven-3.8.3\bin;C:\gradle\gradle-7.6\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET MAVEN_OPTS=-Xmx4g
- cmd: SET JAVA_OPTS=-Xmx4g
- cmd: SET M2_HOME=C:\maven\apache-maven-3.8.3
Expand Down
6 changes: 3 additions & 3 deletions modules/openapi-generator-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
= OpenAPI Generator Gradle Plugin

This document describes the gradle plugin for OpenAPI Generator.
This document describes the Gradle plugin for OpenAPI Generator.

This gradle plugin offers a declarative DSL via _extensions_ (these are Gradle project extensions).
This Gradle plugin offers a declarative DSL via _extensions_ (these are Gradle project extensions).
These map almost fully 1:1 with the options you'd pass to the CLI or Maven plugin. The plugin maps the extensions to a task of the same name to provide a clean API. If you're interested in the extension/task mapping concept from a high-level, you can https://docs.gradle.org/current/userguide/custom_plugins.html#sec:mapping_extension_properties_to_task_properties[check out Gradle's docs].

== Tasks
Expand Down Expand Up @@ -37,7 +37,7 @@ compileJava.dependsOn tasks.openApiGenerate
```
====

All extensions can be rewritten as tasks. Where you can have only a single extension defined in your gradle file, you may have multiple tasks.
All extensions can be rewritten as tasks. Where you can have only a single extension defined in your Gradle file, you may have multiple tasks.

.One Extension, multiple tasks
[source,groovy]
Expand Down
256 changes: 100 additions & 156 deletions modules/openapi-generator-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,84 +1,56 @@
buildscript {
ext.kotlin_version = '1.3.30'
repositories {
mavenLocal()
maven { url "https://repo1.maven.org/maven2" }
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.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "gradle.plugin.org.gradle.kotlin:gradle-kotlin-dsl-plugins:1.1.3"
classpath "com.gradle.publish:plugin-publish-plugin:0.11.0"
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.20.0"
classpath "de.marcphilipp.gradle:nexus-publish-plugin:0.2.0"
}
}
import io.github.gradlenexus.publishplugin.CloseNexusStagingRepository
import io.github.gradlenexus.publishplugin.ReleaseNexusStagingRepository
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.gradle.plugin-publish") version "1.0.0"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("java-gradle-plugin")
id("maven-publish")
id("org.gradle.kotlin.kotlin-dsl") version "2.4.1"
id("org.jetbrains.kotlin.jvm") version "1.7.10"
id("signing")
}

group = "org.openapitools"
version = "$openApiGeneratorVersion"
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

group 'org.openapitools'
// Shared OpenAPI Generator version be passed via command line arg as -PopenApiGeneratorVersion=VERSION
version "$openApiGeneratorVersion"
description = """
This plugin supports common functionality found in Open API Generator CLI as a gradle plugin.
This plugin supports common functionality found in Open API Generator CLI as a Gradle plugin.

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: 'com.gradle.plugin-publish'
apply plugin: 'java-gradle-plugin'
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
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

repositories {
mavenLocal()
maven { url "https://repo1.maven.org/maven2" }
maven {
url "https://oss.sonatype.org/content/repositories/releases/"
}
mavenCentral()
maven {
name = "Sonatype Snapshots"
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
jcenter()
}

dependencies {
compile gradleApi()
// Shared OpenAPI Generator version be passed via command line arg as -PopenApiGeneratorVersion=VERSION
compile "org.openapitools:openapi-generator:$openApiGeneratorVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

testCompile 'org.testng:testng:6.9.6',
"org.jetbrains.kotlin:kotlin-test:$kotlin_version"

testCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
implementation("org.openapitools:openapi-generator:$openApiGeneratorVersion")
testImplementation("org.jetbrains.kotlin:kotlin-test-testng:1.7.10")
}

test {
tasks.named("test", Test).configure {
useTestNG()
testClassesDirs = files(project.tasks.compileTestKotlin.destinationDir)
testLogging.showStandardStreams = false

beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}

failFast = true

onOutput { descriptor, event ->
// SLF4J may complain about multiple bindings depending on how this is run.
// This is just a warning, but can make test output less readable. So we ignore it specifically.
Expand All @@ -88,133 +60,105 @@ test {
}
}

task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}

task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}

artifacts {
archives javadocJar, sourcesJar
tasks.withType(KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
}

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 = "https://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'
}
}
}
tasks.withType(Javadoc).configureEach {
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption("html5", true)
}
}

nexusStaging {
username = project.properties["ossrhUsername"]
password = project.properties["ossrhPassword"]
tasks.withType(CloseNexusStagingRepository).configureEach {
onlyIf { nexusPublishing.useStaging.get() }
}

nexusPublishing {
// To retrieve: ./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="$SIGNING_SECRET" getStagingProfile --no-daemon
stagingProfileId = "456297f829bbbe"
tasks.withType(ReleaseNexusStagingRepository).configureEach {
onlyIf { nexusPublishing.useStaging.get() }
}

gradlePlugin {
website = "https://openapi-generator.tech/"
vcsUrl = "https://github.com/OpenAPITools/openapi-generator"
plugins {
openApiGenerator {
id = 'org.openapi.generator'
implementationClass = 'org.openapitools.generator.gradle.plugin.OpenApiGeneratorPlugin'
id = "org.openapi.generator"
description = "OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)."
displayName = "OpenAPI Generator Gradle Plugin"
implementationClass = "org.openapitools.generator.gradle.plugin.OpenApiGeneratorPlugin"
tags.addAll("openapi-3.0", "openapi-2.0", "openapi", "swagger", "codegen", "sdk")
}
}
}

pluginBundle {
// These settings are set for the whole plugin bundle
website = 'https://openapi-generator.tech/'
vcsUrl = 'https://github.com/OpenAPITools/openapi-generator'
description = 'OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)'
nexusPublishing {
repositories {
sonatype {
username = project.properties["ossrhUsername"]
password = project.properties["ossrhPassword"]

plugins {
// first plugin
openApiGenerator {
id = 'org.openapi.generator'
displayName = 'OpenAPI Generator Gradle Plugin'
tags = ['openapi-3.0', 'openapi-2.0', 'openapi', 'swagger', 'codegen', 'sdk']
version = "$openApiGeneratorVersion"
group = "org.openapitools"
// To retrieve: ./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="$SIGNING_SECRET" getStagingProfile
stagingProfileId = "456297f829bbbe"
}
}
}

// signing will require three keys to be defined: signing.keyId, signing.password, and signing.secretKeyRingFile.
// These can be passed to the gradle command:
// Signing requires 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("publishPluginMavenPublicationToNexusRepository") ) }
sign publishing.publications.mavenJava
}

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
required { isReleaseVersion && gradle.taskGraph.hasTask("publishPluginMavenPublicationToSonatypeRepository") }
sign(publishing.publications)
}

javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
// afterEvaluate is necessary because java-gradle-plugin
// creates its publications in an afterEvaluate callback
afterEvaluate {
tasks.named("publishToSonatype").configure {
dependsOn("check")
}
}

tasks {
closeRepository {
onlyIf { nexusPublishing.useStaging.get() }
}
releaseRepository{
onlyIf { nexusPublishing.useStaging.get() }
publishing {
publications {
pluginMaven {
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 = "https://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"
}
}
}
}
}
}

publishToNexus.dependsOn 'check'
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading