From 5d02696a75ffd7a1d5b9168c50d6de58b0e328d7 Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Tue, 20 Feb 2024 10:46:42 -0800 Subject: [PATCH] Use Gradle typed project accessors This change activates the `TYPESAFE_PROJECT_ACCESSORS` feature preview in Gradle, and switches to such accessors instead of string-based project references, where possible Relates-To: apple/pkl#204 Signed-off-by: Sam Gammon --- bench/bench.gradle.kts | 2 +- docs/docs.gradle.kts | 8 ++++---- pkl-cli/pkl-cli.gradle.kts | 10 +++++----- pkl-codegen-java/pkl-codegen-java.gradle.kts | 10 +++++----- pkl-codegen-kotlin/pkl-codegen-kotlin.gradle.kts | 10 +++++----- pkl-commons-cli/pkl-commons-cli.gradle.kts | 6 +++--- pkl-commons-test/pkl-commons-test.gradle.kts | 2 +- pkl-config-java/pkl-config-java.gradle.kts | 4 ++-- pkl-config-kotlin/pkl-config-kotlin.gradle.kts | 4 ++-- pkl-core/pkl-core.gradle.kts | 4 ++-- pkl-doc/pkl-doc.gradle.kts | 8 ++++---- pkl-executor/pkl-executor.gradle.kts | 4 ++-- pkl-gradle/pkl-gradle.gradle.kts | 6 +++--- pkl-server/pkl-server.gradle.kts | 4 ++-- pkl-tools/pkl-tools.gradle.kts | 12 ++++++------ settings.gradle.kts | 2 ++ 16 files changed, 49 insertions(+), 47 deletions(-) diff --git a/bench/bench.gradle.kts b/bench/bench.gradle.kts index c26674800..e34fec168 100644 --- a/bench/bench.gradle.kts +++ b/bench/bench.gradle.kts @@ -10,7 +10,7 @@ val graal: Configuration by configurations.creating @Suppress("UnstableApiUsage") dependencies { - jmh(project(":pkl-core")) + jmh(projects.pklCore) // necessary because antlr4-runtime is declared as implementation dependency in pkl-core.gradle jmh(libs.antlrRuntime) truffle(libs.truffleApi) diff --git a/docs/docs.gradle.kts b/docs/docs.gradle.kts index 77d90f9f1..e3b1b7a19 100644 --- a/docs/docs.gradle.kts +++ b/docs/docs.gradle.kts @@ -20,10 +20,10 @@ sourceSets { } dependencies { - testImplementation(project(":pkl-core")) - testImplementation(project(":pkl-config-java")) - testImplementation(project(":pkl-config-kotlin")) - testImplementation(project(":pkl-commons-test")) + testImplementation(projects.pklCore) + testImplementation(projects.pklConfigJava) + testImplementation(projects.pklConfigKotlin) + testImplementation(projects.pklCommonsTest) testImplementation(libs.junitEngine) testImplementation(libs.antlrRuntime) } diff --git a/pkl-cli/pkl-cli.gradle.kts b/pkl-cli/pkl-cli.gradle.kts index dcb19f22b..393d11019 100644 --- a/pkl-cli/pkl-cli.gradle.kts +++ b/pkl-cli/pkl-cli.gradle.kts @@ -38,23 +38,23 @@ dependencies { compileOnly(libs.svm) // CliEvaluator exposes PClass - api(project(":pkl-core")) + api(projects.pklCore) // CliEvaluatorOptions exposes CliBaseOptions - api(project(":pkl-commons-cli")) + api(projects.pklCommonsCli) - implementation(project(":pkl-commons")) + implementation(projects.pklCommons) implementation(libs.jansi) implementation(libs.jlineReader) implementation(libs.jlineTerminal) implementation(libs.jlineTerminalJansi) - implementation(project(":pkl-server")) + implementation(projects.pklServer) implementation(libs.clikt) { // force clikt to use our version of the kotlin stdlib exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8") exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-common") } - testImplementation(project(":pkl-commons-test")) + testImplementation(projects.pklCommonsTest) stagedMacAmd64Executable(files("$buildDir/executable/pkl-macos-amd64")) stagedMacAarch64Executable(files("$buildDir/executable/pkl-macos-aarch64")) diff --git a/pkl-codegen-java/pkl-codegen-java.gradle.kts b/pkl-codegen-java/pkl-codegen-java.gradle.kts index 20b0e3095..17087a12f 100644 --- a/pkl-codegen-java/pkl-codegen-java.gradle.kts +++ b/pkl-codegen-java/pkl-codegen-java.gradle.kts @@ -6,14 +6,14 @@ plugins { dependencies { // CliJavaCodeGeneratorOptions exposes CliBaseOptions - api(project(":pkl-commons-cli")) + api(projects.pklCommonsCli) - implementation(project(":pkl-commons")) - implementation(project(":pkl-core")) + implementation(projects.pklCommons) + implementation(projects.pklCore) implementation(libs.javaPoet) - testImplementation(project(":pkl-config-java")) - testImplementation(project(":pkl-commons-test")) + testImplementation(projects.pklConfigJava) + testImplementation(projects.pklCommonsTest) } // with `org.gradle.parallel=true` and without the line below, `test` strangely runs into: diff --git a/pkl-codegen-kotlin/pkl-codegen-kotlin.gradle.kts b/pkl-codegen-kotlin/pkl-codegen-kotlin.gradle.kts index 1bc2d9d87..fb1d09dc6 100644 --- a/pkl-codegen-kotlin/pkl-codegen-kotlin.gradle.kts +++ b/pkl-codegen-kotlin/pkl-codegen-kotlin.gradle.kts @@ -25,15 +25,15 @@ tasks.jar { } dependencies { - implementation(project(":pkl-commons")) - api(project(":pkl-commons-cli")) - api(project(":pkl-core")) + implementation(projects.pklCommons) + api(projects.pklCommonsCli) + api(projects.pklCore) implementation(libs.kotlinPoet) implementation(libs.kotlinReflect) - testImplementation(project(":pkl-config-kotlin")) - testImplementation(project(":pkl-commons-test")) + testImplementation(projects.pklConfigKotlin) + testImplementation(projects.pklCommonsTest) testImplementation(libs.kotlinCompilerEmbeddable) testRuntimeOnly(libs.kotlinScriptingCompilerEmbeddable) testRuntimeOnly(libs.kotlinScriptUtil) diff --git a/pkl-commons-cli/pkl-commons-cli.gradle.kts b/pkl-commons-cli/pkl-commons-cli.gradle.kts index e24e1fefa..d836b138c 100644 --- a/pkl-commons-cli/pkl-commons-cli.gradle.kts +++ b/pkl-commons-cli/pkl-commons-cli.gradle.kts @@ -5,15 +5,15 @@ plugins { } dependencies { - api(project(":pkl-core")) + api(projects.pklCore) api(libs.clikt) { // force clikt to use our version of the kotlin stdlib exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8") exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-common") } - implementation(project(":pkl-commons")) - testImplementation(project(":pkl-commons-test")) + implementation(projects.pklCommons) + testImplementation(projects.pklCommonsTest) } publishing { diff --git a/pkl-commons-test/pkl-commons-test.gradle.kts b/pkl-commons-test/pkl-commons-test.gradle.kts index 9a22956b3..7a3c60003 100644 --- a/pkl-commons-test/pkl-commons-test.gradle.kts +++ b/pkl-commons-test/pkl-commons-test.gradle.kts @@ -11,7 +11,7 @@ dependencies { api(libs.junitApi) api(libs.junitEngine) api(libs.junitParams) - api(project(":pkl-commons")) // for convenience + api(projects.pklCommons) // for convenience implementation(libs.assertj) } diff --git a/pkl-config-java/pkl-config-java.gradle.kts b/pkl-config-java/pkl-config-java.gradle.kts index 7997eced2..749d26415 100644 --- a/pkl-config-java/pkl-config-java.gradle.kts +++ b/pkl-config-java/pkl-config-java.gradle.kts @@ -62,7 +62,7 @@ sourceSets.getByName("test") { dependencies { // "api" because ConfigEvaluator extends Evaluator - api(project(":pkl-core")) + api(projects.pklCore) implementation(libs.geantyref) @@ -70,7 +70,7 @@ dependencies { firstPartySourcesJars(project(":pkl-core", "sourcesJar")) - pklCodegenJava(project(":pkl-codegen-java")) + pklCodegenJava(projects.pklCodegenJava) } tasks.shadowJar { diff --git a/pkl-config-kotlin/pkl-config-kotlin.gradle.kts b/pkl-config-kotlin/pkl-config-kotlin.gradle.kts index 6ee31ca24..bbef36f0a 100644 --- a/pkl-config-kotlin/pkl-config-kotlin.gradle.kts +++ b/pkl-config-kotlin/pkl-config-kotlin.gradle.kts @@ -16,11 +16,11 @@ val pklCodegenKotlin: Configuration by configurations.creating configurations.api.get().extendsFrom(pklConfigJava) dependencies { - pklConfigJava(project(":pkl-config-java")) + pklConfigJava(projects.pklConfigJava) pklConfigJavaAll(project(":pkl-config-java", "fatJar")) - pklCodegenKotlin(project(":pkl-codegen-kotlin")) + pklCodegenKotlin(projects.pklCodegenKotlin) implementation(libs.kotlinReflect) diff --git a/pkl-core/pkl-core.gradle.kts b/pkl-core/pkl-core.gradle.kts index fe3daa730..0c5b611cc 100644 --- a/pkl-core/pkl-core.gradle.kts +++ b/pkl-core/pkl-core.gradle.kts @@ -44,7 +44,7 @@ dependencies { compileOnly(libs.jsr305) // pkl-core implements pkl-executor's ExecutorSpi, but the SPI doesn't ship with pkl-core - compileOnly(project(":pkl-executor")) + compileOnly(projects.pklExecutor) implementation(libs.antlrRuntime) implementation(libs.truffleApi) @@ -56,7 +56,7 @@ dependencies { implementation(libs.snakeYaml) - testImplementation(project(":pkl-commons-test")) + testImplementation(projects.pklCommonsTest) add("generatorImplementation", libs.javaPoet) add("generatorImplementation", libs.truffleApi) diff --git a/pkl-doc/pkl-doc.gradle.kts b/pkl-doc/pkl-doc.gradle.kts index a222b94a3..c880aea10 100644 --- a/pkl-doc/pkl-doc.gradle.kts +++ b/pkl-doc/pkl-doc.gradle.kts @@ -12,9 +12,9 @@ plugins { val graalVmBaseDir = buildInfo.graalVm.baseDir dependencies { - implementation(project(":pkl-core")) - implementation(project(":pkl-commons-cli")) - implementation(project(":pkl-commons")) + implementation(projects.pklCore) + implementation(projects.pklCommonsCli) + implementation(projects.pklCommons) implementation(libs.commonMark) implementation(libs.commonMarkTables) implementation(libs.kotlinxHtml) @@ -24,7 +24,7 @@ dependencies { exclude(group = "org.jetbrains.kotlin") } - testImplementation(project(":pkl-commons-test")) + testImplementation(projects.pklCommonsTest) testImplementation(libs.jimfs) // Graal.JS diff --git a/pkl-executor/pkl-executor.gradle.kts b/pkl-executor/pkl-executor.gradle.kts index a04a30018..1956a9db4 100644 --- a/pkl-executor/pkl-executor.gradle.kts +++ b/pkl-executor/pkl-executor.gradle.kts @@ -16,8 +16,8 @@ dependencies { implementation(libs.slf4jApi) - testImplementation(project(":pkl-commons-test")) - testImplementation(project(":pkl-core")) + testImplementation(projects.pklCommonsTest) + testImplementation(projects.pklCore) testImplementation(libs.slf4jSimple) } diff --git a/pkl-gradle/pkl-gradle.gradle.kts b/pkl-gradle/pkl-gradle.gradle.kts index f38a930e3..24a5d719c 100644 --- a/pkl-gradle/pkl-gradle.gradle.kts +++ b/pkl-gradle/pkl-gradle.gradle.kts @@ -12,9 +12,9 @@ plugins { } dependencies { - // Declare a `compileOnly` dependency on `project(":pkl-tools")` + // Declare a `compileOnly` dependency on `projects.pklTools` // to ensure correct code navigation in IntelliJ. - compileOnly(project(":pkl-tools")) + compileOnly(projects.pklTools) // Declare a `runtimeOnly` dependency on `project(":pkl-tools", "fatJar")` // to ensure that the published plugin @@ -31,7 +31,7 @@ dependencies { runtimeOnly(project(":pkl-tools", "fatJar")) } - testImplementation(project(":pkl-commons-test")) + testImplementation(projects.pklCommonsTest) } publishing { diff --git a/pkl-server/pkl-server.gradle.kts b/pkl-server/pkl-server.gradle.kts index 6bfdb5a29..f2d729ac5 100644 --- a/pkl-server/pkl-server.gradle.kts +++ b/pkl-server/pkl-server.gradle.kts @@ -5,12 +5,12 @@ plugins { } dependencies { - implementation(project(":pkl-core")) + implementation(projects.pklCore) implementation(libs.msgpack) implementation(libs.truffleApi) implementation(libs.antlrRuntime) - testImplementation(project(":pkl-commons-test")) + testImplementation(projects.pklCommonsTest) } tasks.test { diff --git a/pkl-tools/pkl-tools.gradle.kts b/pkl-tools/pkl-tools.gradle.kts index 416393918..6abfdfb36 100644 --- a/pkl-tools/pkl-tools.gradle.kts +++ b/pkl-tools/pkl-tools.gradle.kts @@ -18,12 +18,12 @@ dependencies { // can declare a normal project dependency on this project, // which is desirable for IntelliJ integration. // The published fat JAR doesn't declare any dependencies. - api(project(":pkl-cli")) - api(project(":pkl-codegen-java")) - api(project(":pkl-codegen-kotlin")) - api(project(":pkl-config-java")) - api(project(":pkl-core")) - api(project(":pkl-doc")) + api(projects.pklCli) + api(projects.pklCodegenJava) + api(projects.pklCodegenKotlin) + api(projects.pklConfigJava) + api(projects.pklCore) + api(projects.pklDoc) // used by `pklFatJar` plugin (ideally this would be inferred automatically) firstPartySourcesJars(project(":pkl-cli", "sourcesJar")) diff --git a/settings.gradle.kts b/settings.gradle.kts index a689a007c..6d1da1dcd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -47,3 +47,5 @@ if (gradle.startParameter.taskNames.contains("updateDependencyLocks") || for (prj in rootProject.children) { prj.buildFileName = "${prj.name}.gradle.kts" } + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")