mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
|
||||
}
|
||||
|
||||
private fun writeBuildFile() {
|
||||
val kotlinVersion = "1.6.0"
|
||||
val kotlinVersion = "2.0.21"
|
||||
|
||||
writeFile(
|
||||
"build.gradle",
|
||||
|
||||
Reference in New Issue
Block a user