Skip to content

Commit

Permalink
Update from Gradle 6.9 to Gradle 8.0 (#168)
Browse files Browse the repository at this point in the history
* Bump Gradle Wrapper to Gradle 8.0 (from 6.9)

* Remove outdated DSL: kotlinDslPluginOptions.experimentalWarning

> Configure project :buildSrc
e: P:\projects\contrib\github-nexus-publish-plugin\buildSrc\build.gradle.kts:14:5: Unresolved reference: experimentalWarning

> Configure project :buildSrc
The KotlinDslPluginOptions.experimentalWarning property has been deprecated. This is scheduled to be removed in Gradle 8.0. Flag has no effect since `kotlin-dsl` no longer relies on experimental features.
        at Build_gradle$3.execute(build.gradle.kts:14)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)

* Update Shadow plugin, because 6.1.0 is not compatible with Gradle 7.x and Gradle 8.x

* What went wrong:
org/gradle/api/plugins/MavenPlugin

* Try:
> Run with --info or --debug option to get more log output.

* Exception is:
java.lang.NoClassDefFoundError: org/gradle/api/plugins/MavenPlugin
        at com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin$1.execute(ShadowJavaPlugin.groovy:101)

* Regenerate Gradle Wrapper with Gradle 8.0

* Bump Versions plugin, Gradle 7.x support is full-blown from 0.43.0

Gradle 7.4 fixes:
https://github.com/ben-manes/gradle-versions-plugin/releases/tag/v0.42.0

Gradle 7 required:
https://github.com/ben-manes/gradle-versions-plugin/releases/tag/v0.43.0

* Bump plugin-publish plugin to 1.x

pluginBundle was deprecated in Gradle 7.6 and removed in Gradle 8.0:
https://plugins.gradle.org/plugin/com.gradle.plugin-publish/1.0.0

maven-publish is auto-applied

* Lock in Java compilation version to the same as Kotlin, otherwise things can go wrong.

> Task :compileKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> 'compileJava' task (current target is 11) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

* ConfigureUtil is deprecated in Gradle 7.1 and started nagging in Gradle 7.6. Building with Gradle 8.0 will obviously also warn. Let's suppress it for now, this will be dealt with in #152

* Add support for Spotless on Windows

Also in #167, but it's annoying not being able to get a green build locally.

* Move sourceCompatibility to the existing java block

* Keep building Kotlin with 1.3 compatibility, otherwise there are failures on older Gradle versions.

For example: NexusPublishPluginTests.should close staging repository
```
> Task :closeSonatypeStagingRepository FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':closeSonatypeStagingRepository'.
> kotlin.jvm.internal.PropertyReference1Impl.<init>(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
```

* Silence unnecessary build warnings.

> Task :compileKotlin
w: API version 1.3 is deprecated and its support will be removed in a future version of Kotlin

> Task :compileTestKotlin
w: API version 1.3 is deprecated and its support will be removed in a future version of Kotlin

> Task :compileCompatTestKotlin
w: API version 1.3 is deprecated and its support will be removed in a future version of Kotlin

* Remove duplicate calls to withSourcesJar

It's done by the plugin-publish plugin too.
In the Gradle Metadata (.module) it duplicates artifacts if called multiple times.

* Remove unnecessary shadowed configuration

There is built-in support for standard configuration in plugin-publish and shadow plugins.

* Remove unidentified workaround

It doesn't change anything in the output publishToMavenLocal, it was probably for an older combination of Gradle / plugin-publish / shadow plugins.

* Work around unnecessary ClassPath in MANIFEST.MF

* Downgrade language version from Kotlin 1.8 to Kotlin 1.3 to generate compatible @kotlin.Metadata in the .class files.

* Remove unrelated change.

* Diagnose #168 (comment)

* Revert "Diagnose #168 (comment)"

This reverts commit c14acc5.

* Mention Kotlin 1.3 #168 (comment)

* Reduce CI load, re #168 (comment)

* Diagnose #168 (comment)

* Revert "Diagnose #168 (comment)"

This reverts commit 8488741.

* Add sha256 to wrapper
  • Loading branch information
TWiStErRob committed Feb 17, 2023
1 parent 0843160 commit ea86f41
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 170 deletions.
82 changes: 35 additions & 47 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
`maven-publish`
id("com.gradle.plugin-publish") version "0.21.0"
id("com.gradle.plugin-publish") version "1.1.0"
id("com.diffplug.spotless") version "6.0.0"
id("com.github.johnrengelman.shadow") version "6.1.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("org.jetbrains.gradle.plugin.idea-ext")
id("com.github.ben-manes.versions") version "0.39.0"
id("com.github.ben-manes.versions") version "0.45.0"
id("org.ajoberstar.stutter") version "0.6.0"
}

Expand All @@ -21,19 +20,17 @@ val readableName = "Nexus Publish Plugin"
description = "Gradle Plugin for publishing to Nexus that automates creating, closing, and releasing staging repositories"
val repoUrl = "https://github.com/gradle-nexus/publish-plugin"

pluginBundle {
description = project.description
website = repoUrl
vcsUrl = repoUrl
tags = listOf("publishing", "maven", "nexus")
}

@Suppress("UnstableApiUsage") // Using this DSL is the only way on Gradle 8.0, could still change slightly in the future.
gradlePlugin {
website.set(repoUrl)
vcsUrl.set(repoUrl)
plugins {
create("nexusPublish") {
id = "io.github.gradle-nexus.publish-plugin"
displayName = readableName
implementationClass = "io.github.gradlenexus.publishplugin.NexusPublishPlugin"
description = project.description
tags.addAll("publishing", "maven", "nexus")
}
}
}
Expand Down Expand Up @@ -68,21 +65,18 @@ idea {
}
}

val shadowed by configurations.creating
configurations {
compileOnly {
extendsFrom(shadowed)
}
testImplementation {
extendsFrom(shadowed)
exclude(group = "junit", module = "junit")
}
// Workaround https://github.com/gradle/gradle/issues/23928
shadow.configure { afterEvaluate { this@configure.dependencies.remove(project.dependencies.gradleApi()) } }
}

dependencies {
shadowed("com.squareup.retrofit2:retrofit:2.9.0")
shadowed("com.squareup.retrofit2:converter-gson:2.9.0")
shadowed("net.jodah:failsafe:2.4.3")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("net.jodah:failsafe:2.4.3")

testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation("com.github.tomakehurst:wiremock:2.27.2")
Expand All @@ -93,8 +87,8 @@ dependencies {
}

java {
withJavadocJar()
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

stutter {
Expand Down Expand Up @@ -141,21 +135,34 @@ sourceSets {
}
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
}

tasks {
withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
afterEvaluate {
// This needs to be in an afterEvaluate block,
// because otherwise KotlinDslCompilerPlugins would win, and override what we've set to Kotlin 1.8.
withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
// Supporting Gradle 5.0+ needs to use Kotlin 1.3.
// See https://docs.gradle.org/current/userguide/compatibility.html
kotlinOptions.apiVersion = "1.3"
// Theoretically we could use newer language version here,
// but sadly the @kotlin.Metadata created on the classes would be incompatible with Kotlin 1.3 consumers.
kotlinOptions.languageVersion = "1.3"
doFirst {
if (kotlinOptions.apiVersion == "1.3") {
// Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin".
kotlinOptions.freeCompilerArgs += "-Xsuppress-version-warnings"
} else {
TODO("Remove -Xsuppress-version-warnings suppression, or change the condition to ${kotlinOptions.languageVersion}")
}
}
}
}
val relocateShadowJar by registering(ConfigureShadowRelocation::class) {
target = shadowJar.get()
prefix = "io.github.gradlenexus.publishplugin.shadow"
}
shadowJar {
dependsOn(relocateShadowJar)
configurations = listOf(shadowed)
exclude("META-INF/maven/**", "META-INF/proguard/**", "META-INF/*.kotlin_module")
manifest {
attributes["Implementation-Version"] = project.version
Expand Down Expand Up @@ -205,25 +212,6 @@ tasks {
}
}

configurations {
configureEach {
outgoing {
val removed = artifacts.removeIf { it.classifier.isNullOrEmpty() }
if (removed) {
artifact(tasks.shadowJar) {
classifier = ""
}
}
}
}
// used by plugin-publish plugin
archives {
outgoing {
artifact(tasks.named("sourcesJar"))
}
}
}

publishing {
publications {
afterEvaluate {
Expand Down
4 changes: 0 additions & 4 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ repositories {
dependencies {
implementation("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:0.7")
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
distributionSha256Sum=4159b938ec734a8388ce03f52aa8f3c7ed0d31f5438622545de4f83a89b79788
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit ea86f41

Please sign in to comment.