Bump Gradle to 9.1.0 (#1228)

* Bump Gradle to 9.1.0
* Bump foojay resolver to 1.0.0
* Fix build logic on windows

Also, remove support for kotlin gradle plugin less than 1.8.x, because:

* Class `org.gradle.api.plugins.Convention` is no longer available in the classpath in Gradle
* Continued support for legacy plugin would require heavy reflection, which is brittle and hard to verify
* Kotlin 1.7 is 3 years old and no longer updated
This commit is contained in:
Daniel Chao
2025-10-08 08:54:43 -07:00
committed by GitHub
parent 55eac2088b
commit cf9d87373d
7 changed files with 8 additions and 69 deletions

View File

@@ -70,7 +70,7 @@ open class MergeSourcesJars : DefaultTask() {
val details = this
if (details.isDirectory) return@visit
var path = details.relativePath.parent.pathString
var path = details.relativePath.parent!!.pathString
val relocatedPath = relocatedPaths.keys.find { path.startsWith(it) }
if (relocatedPath != null) {
path = path.replace(relocatedPath, relocatedPaths.getValue(relocatedPath))
@@ -101,7 +101,7 @@ open class MergeSourcesJars : DefaultTask() {
project.zipTree(jar).visit {
val details = this
if (details.isDirectory) return@visit // avoid adding empty dirs
result.add(details.relativePath.parent.pathString)
result.add(details.relativePath.parent!!.pathString)
}
}
return result

View File

@@ -81,7 +81,7 @@ plugins.withType(MavenPublishPlugin::class).configureEach {
repositories {
maven {
name = "projectLocal" // affects task names
url = uri("file:///$rootDir/build/m2")
url = rootDir.resolve("build/m2").toURI()
}
}
// use resolved/locked (e.g., `1.15`)

View File

@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionSha256Sum=a17ddd85a26b6a7f5ddb71ff8b05fc5104c0202c6e64782429790c933686c806
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

View File

@@ -89,7 +89,7 @@ gradlePlugin {
gradlePluginTests {
// keep in sync with `PklPlugin.MIN_GRADLE_VERSION`
minGradleVersion = GradleVersion.version("8.2")
maxGradleVersion = GradleVersion.version("8.99")
maxGradleVersion = GradleVersion.version("9.99")
skippedGradleVersions = listOf()
}

View File

@@ -16,7 +16,6 @@
package org.pkl.gradle;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.LinkedHashSet;
@@ -30,7 +29,6 @@ import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Transformer;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.plugins.Convention;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
@@ -591,69 +589,10 @@ public class PklPlugin implements Plugin<Project> {
}
private Optional<SourceDirectorySet> getKotlinSourceDirectorySet(SourceSet sourceSet) {
// First, try loading it as an extension - 1.8+ version of Kotlin plugin does this.
var kotlinExtension = sourceSet.getExtensions().findByName("kotlin");
if (kotlinExtension instanceof SourceDirectorySet sourceDirSet) {
return Optional.of(sourceDirSet);
}
// Otherwise, try to load it as a convention. First, we attempt to get the convention
// object of the source set via the HasConvention.getConvention() method.
// We don't use the HasConvention interface directly as it is deprecated.
// Then, we extract the `kotlin` plugin from the convention, which "provides"
// the additional properties for the source set. This plugin has a method named
// `getKotlin` whose return type is a source directory set, so we use reflection
// to call it too.
// Basically, this is equivalent to calling `sourceSet.kotlin`, where `kotlin` is a property
// contributed by a plugin also named `kotlin`.
// This part of logic can be removed once we stop supporting Kotlin plugin with version
// less than 1.8.x.
try {
var getConventionMethod = sourceSet.getClass().getMethod("getConvention");
var convention = getConventionMethod.invoke(sourceSet);
//noinspection deprecation
if (convention instanceof Convention c) {
//noinspection deprecation
var kotlinSourceSet = c.getPlugins().get("kotlin");
if (kotlinSourceSet == null) {
project
.getLogger()
.debug(
"Cannot obtain Kotlin source directory set of source set [{}], "
+ "it does not have the `kotlin` convention plugin",
sourceSet.getName());
return Optional.empty();
}
var getKotlinMethod = kotlinSourceSet.getClass().getMethod("getKotlin");
var kotlinSourceDirectorySet = getKotlinMethod.invoke(kotlinSourceSet);
if (kotlinSourceDirectorySet instanceof SourceDirectorySet sourceDirSet) {
return Optional.of(sourceDirSet);
}
project
.getLogger()
.debug(
"Cannot obtain Kotlin source directory set, sourceSets.{}.kotlin is of wrong type",
sourceSet.getName());
} else {
project
.getLogger()
.debug(
"Cannot obtain Kotlin source directory set, sourceSets.{}.convention "
+ "returned unexpected type",
sourceSet.getName());
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
project
.getLogger()
.debug(
"Cannot obtain Kotlin source directory set of source set [{}] via a convention",
sourceSet.getName(),
e);
}
return Optional.empty();
}
}

View File

@@ -108,7 +108,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
}
private fun writeBuildFile() {
val kotlinVersion = "1.6.0"
val kotlinVersion = "2.0.21"
writeFile(
"build.gradle",

View File

@@ -60,7 +60,7 @@ pluginManagement {
}
}
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version ("0.8.0") }
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version ("1.0.0") }
@Suppress("UnstableApiUsage") dependencyResolutionManagement { repositories { mavenCentral() } }