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
This commit is contained in:
odenix
2026-04-08 16:09:37 -07:00
committed by GitHub
parent ff6f7223d3
commit fdeb568343
7 changed files with 16 additions and 14 deletions

View File

@@ -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<String>
@TaskAction
@Suppress("unused")
fun buildJar() {
val inFile = inJar.get().asFile
val outFile = outJar.get().asFile

View File

@@ -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(
"(?<!(\\w|\\.))(" + relocatedPkgs.keys.joinToString("|") { it.replace(".", "\\.") } + ")"
"(?<!([\\w.]))(" + relocatedPkgs.keys.joinToString("|") { it.replace(".", "\\.") } + ")"
)
val sourceFileExts = sourceFileExtensions.get()

View File

@@ -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.
@@ -102,6 +102,7 @@ abstract class NativeImageBuild : DefaultTask() {
}
@TaskAction
@Suppress("unused")
protected fun run() {
execOperations.exec {
val exclusions =

View File

@@ -52,14 +52,14 @@ configurations.all {
}
plugins.withType(JavaPlugin::class).configureEach {
tasks.withType<JavaCompile>().configureEach { options.release = 17 }
tasks.withType<JavaCompile>().configureEach { options.release = buildInfo.jvmTarget }
}
tasks.withType<KotlinJvmCompile>().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

View File

@@ -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") {

View File

@@ -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<JavaLauncher>? = null)
outputFile.get().asFile.toPath().apply {
try {
parent.createDirectories()
} catch (ignored: java.nio.file.FileAlreadyExistsException) {}
} catch (_: java.nio.file.FileAlreadyExistsException) {}
writeText("OK")
}
}

View File

@@ -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")
}
}