Added support for external readers in Gradle plugins (#1578)

Adds support for configuring external module and resource readers in the Gradle plugin
This commit is contained in:
Vladimir Matveev
2026-05-14 11:18:22 -07:00
committed by GitHub
parent 1b6e89c971
commit 2fe565a0f2
13 changed files with 644 additions and 47 deletions
+49 -3
View File
@@ -63,13 +63,59 @@ sourceSets {
}
}
// Support for testing with a real external reader in tests - this builds an additional source set
// into a jar with a main class which provides a simple external reader implementation.
// Then the path to the jar file and the toolchain's `java` binary
// are injected into tests as properties.
val externalReader by sourceSets.creating {}
dependencies { "externalReaderImplementation"(libs.msgpack) }
val externalReaderJar by
tasks.registering(Jar::class) {
description = "Builds an external reader executable jar file"
archiveBaseName = "external-reader"
archiveVersion = ""
// Package all dependencies into the jar (shadow plugin lite).
from(
externalReader.runtimeClasspath.elements.map { locations ->
locations.mapNotNull { location ->
val f = location.asFile
when {
f.isDirectory -> f
f.isFile -> zipTree(f)
else -> null
}
}
}
)
manifest { attributes("Main-Class" to "org.pkl.gradle.test.extreader.Main") }
}
tasks.test {
dependsOn(externalReaderJar)
// Currently the only way to inject system properties from lazy values in Gradle
// is via `jvmArgumentProviders`.
jvmArgumentProviders += CommandLineArgumentProvider {
listOf(
"-DpklGradle.externalReaderJar=" +
externalReaderJar.get().archiveFile.get().asFile.absolutePath,
"-DpklGradle.javaExecutable=" +
javaToolchains.launcherFor(java.toolchain).get().executablePath.asFile.absolutePath,
)
}
}
publishing {
publications {
withType<MavenPublication>().configureEach {
pom {
name.set("pkl-gradle plugin")
url.set("https://github.com/apple/pkl/tree/main/pkl-gradle")
description.set("Gradle plugin for the Pkl configuration language.")
name = "pkl-gradle plugin"
url = "https://github.com/apple/pkl/tree/main/pkl-gradle"
description = "Gradle plugin for the Pkl configuration language."
}
}
}