Skip to content

Commit

Permalink
Make Gradle 7.6 compatable
Browse files Browse the repository at this point in the history
- Kotlin does not support Java 19 as the target bytecode.
  As the default version follows the current Java version,
  a specific target is necessary for release.
- Add a workaround that handles a regression in dependency in Gradle 7.6
  See gradle/gradle#23096 for details.
  • Loading branch information
ikhoon committed Dec 19, 2022
1 parent 1bebf92 commit ad30ad0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/java-shade.gradle
Expand Up @@ -321,8 +321,9 @@ private Configuration configureShadedTestRuntimeConfiguration(
// Skip the excluded dependencies.
return
}

project.dependencies.add(shadedTestRuntime.name, dep)
// Do not use `project.dependencies.add(name, dep)` that discards the classifier of
// a dependency. See https://github.com/gradle/gradle/issues/23096
project.configurations.getByName(shadedTestRuntime.name).dependencies.add(dep)
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion lib/java.gradle
@@ -1,11 +1,13 @@
def buildJdkVersion = 17
def buildJdkVersion = Integer.parseInt(JavaVersion.current().getMajorVersion())
if (rootProject.hasProperty('buildJdkVersion')) {
def jdkVersion = Integer.parseInt(rootProject.findProperty('buildJdkVersion'))
if (buildJdkVersion != jdkVersion) {
buildJdkVersion = jdkVersion
logger.quiet("Overriding JDK for build with ${buildJdkVersion}")
}
}

logger.info("Using JDK ${buildJdkVersion} to build ${project.name}")
rootProject.ext.set("buildJdkVersion", buildJdkVersion)

def testJavaVersion = buildJdkVersion
Expand All @@ -16,6 +18,8 @@ if (rootProject.hasProperty('testJavaVersion')) {
logger.quiet("Overriding JRE for tests with ${testJavaVersion}")
}
}

logger.info("Using JRE ${testJavaVersion} to test ${project.name}")
rootProject.ext.set("testJavaVersion", testJavaVersion)

// Enable checkstyle if the rule file exists.
Expand Down
24 changes: 15 additions & 9 deletions lib/kotlin.gradle
Expand Up @@ -2,15 +2,21 @@ configure(projectsWithFlags('kotlin')) {

apply plugin: 'kotlin'

def target = project.findProperty('javaTargetCompatibility') ?: '1.8'
def compilerArgs = ['-java-parameters', '-Xjsr305=strict', '-Xskip-prerelease-check']
compileKotlin {
kotlinOptions.jvmTarget = target
kotlinOptions.freeCompilerArgs = compilerArgs
}
compileTestKotlin {
kotlinOptions.jvmTarget = target
kotlinOptions.freeCompilerArgs = compilerArgs
// compileJmhKotlin is injected by 'jmh' plugin while a benchmark module is being initialized.
afterEvaluate {
def target = project.tasks.findByName('compileJava')?.targetCompatibility ?:
project.findProperty('javaTargetCompatibility') ?: '1.8'
def compilerArgs = ['-java-parameters', '-Xjsr305=strict', '-Xskip-prerelease-check']
// A workaround to find all Kotlin compilation tasks.
// The standard way, `tasks.withType(KotlinCompile)`, does not work here.
tasks.matching {
def name = it.name
// Expected task names: "compile<Name>Kotlin" or "kaptGenerateStubs<Name>Kotlin"
(name.startsWith("compile") || name.startsWith("kaptGenerateStubs")) && name.endsWith("Kotlin")
}.each { task ->
task.kotlinOptions.jvmTarget = target
task.kotlinOptions.freeCompilerArgs = compilerArgs
}
}

if (!rootProject.hasProperty('noLint')) {
Expand Down

0 comments on commit ad30ad0

Please sign in to comment.