From fdeb5683437407a6052b90f12fabb0ad92003b22 Mon Sep 17 00:00:00 2001 From: odenix Date: Wed, 8 Apr 2026 16:09:37 -0700 Subject: [PATCH] Clean up Kotlin code in buildSrc/ (#1512) - fix most IntelliJ warnings (regex refactoring was done by IDE) - replace hardcoded JVM target versions with BuildInfo.jvmTarget --- buildSrc/src/main/kotlin/ExecutableJar.kt | 3 ++- buildSrc/src/main/kotlin/MergeSourcesJars.kt | 4 ++-- buildSrc/src/main/kotlin/NativeImageBuild.kt | 3 ++- buildSrc/src/main/kotlin/pklAllProjects.gradle.kts | 8 +++----- buildSrc/src/main/kotlin/pklGradlePluginTest.gradle.kts | 4 +++- buildSrc/src/main/kotlin/pklJavaExecutable.gradle.kts | 4 ++-- buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts | 4 ++-- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/buildSrc/src/main/kotlin/ExecutableJar.kt b/buildSrc/src/main/kotlin/ExecutableJar.kt index a558539f..6cbd70b0 100644 --- a/buildSrc/src/main/kotlin/ExecutableJar.kt +++ b/buildSrc/src/main/kotlin/ExecutableJar.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ abstract class ExecutableJar : DefaultTask() { @get:Input abstract val jvmArgs: ListProperty @TaskAction + @Suppress("unused") fun buildJar() { val inFile = inJar.get().asFile val outFile = outJar.get().asFile diff --git a/buildSrc/src/main/kotlin/MergeSourcesJars.kt b/buildSrc/src/main/kotlin/MergeSourcesJars.kt index 7e44b824..9e1551be 100644 --- a/buildSrc/src/main/kotlin/MergeSourcesJars.kt +++ b/buildSrc/src/main/kotlin/MergeSourcesJars.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +57,7 @@ open class MergeSourcesJars : DefaultTask() { // a word or a period character. should catch most cases. val importPattern = Pattern.compile( - "(?().configureEach { options.release = 17 } + tasks.withType().configureEach { options.release = buildInfo.jvmTarget } } tasks.withType().configureEach { compilerOptions { - jvmTarget = JvmTarget.JVM_17 + jvmTarget = JvmTarget.fromTarget(buildInfo.jvmTarget.toString()) freeCompilerArgs.addAll("-Xjsr305=strict", "-Xjvm-default=all") - freeCompilerArgs.add("-Xjdk-release=17") + freeCompilerArgs.add("-Xjdk-release=${buildInfo.jvmTarget}") } } @@ -110,7 +110,6 @@ tasks.withType(Test::class).configureEach { } debugOptions { enabled = System.getProperty("jvmdebug")?.toBoolean() ?: false - @Suppress("UnstableApiUsage") host = "*" port = 5005 suspend = true @@ -121,7 +120,6 @@ tasks.withType(Test::class).configureEach { tasks.withType(JavaExec::class).configureEach { debugOptions { enabled = System.getProperty("jvmdebug")?.toBoolean() ?: false - @Suppress("UnstableApiUsage") host = "*" port = 5005 suspend = true diff --git a/buildSrc/src/main/kotlin/pklGradlePluginTest.gradle.kts b/buildSrc/src/main/kotlin/pklGradlePluginTest.gradle.kts index d950d756..5de3573c 100644 --- a/buildSrc/src/main/kotlin/pklGradlePluginTest.gradle.kts +++ b/buildSrc/src/main/kotlin/pklGradlePluginTest.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ tasks.addRule("Pattern: compatibilityTest[All|Releases|Latest|Candidate|Nightly| val taskName = this val matchResult = Regex("compatibilityTest(.+)").matchEntire(taskName) ?: return@addRule + // https://github.com/gradle/gradle/issues/32599 + @Suppress("DEPRECATION") when (val taskNameSuffix = matchResult.groupValues[1]) { "All" -> task("compatibilityTestAll") { diff --git a/buildSrc/src/main/kotlin/pklJavaExecutable.gradle.kts b/buildSrc/src/main/kotlin/pklJavaExecutable.gradle.kts index dcecc97e..cc51b95a 100644 --- a/buildSrc/src/main/kotlin/pklJavaExecutable.gradle.kts +++ b/buildSrc/src/main/kotlin/pklJavaExecutable.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2025-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,7 +72,7 @@ fun Task.setupTestStartJavaExecutable(launcher: Provider? = null) outputFile.get().asFile.toPath().apply { try { parent.createDirectories() - } catch (ignored: java.nio.file.FileAlreadyExistsException) {} + } catch (_: java.nio.file.FileAlreadyExistsException) {} writeText("OK") } } diff --git a/buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts b/buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts index 96c5b5fd..609a45a6 100644 --- a/buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts +++ b/buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2025-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -161,7 +161,7 @@ val testStartNativeExecutable by outputFile.get().asFile.toPath().apply { try { parent.createDirectories() - } catch (ignored: java.nio.file.FileAlreadyExistsException) {} + } catch (_: java.nio.file.FileAlreadyExistsException) {} writeText("OK") } }