Skip to content

Commit

Permalink
copy JVM target from kotlin compile task
Browse files Browse the repository at this point in the history
(cherry picked from commit bf2ebf0)
  • Loading branch information
neetopia committed Jun 22, 2023
1 parent 5272679 commit 0f4590f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
configureAsAbstractKotlinCompileTool(kspTask as AbstractKotlinCompileTool<*>)
configurePluginOptions(kspTask)
kspTask.compilerOptions.noJdk.value(kotlinCompileTask.compilerOptions.noJdk)
kspTask.compilerOptions.jvmTarget.value(kotlinCompileTask.compilerOptions.jvmTarget)
kspTask.compilerOptions.verbose.convention(kotlinCompilation.compilerOptions.options.verbose)
// Read from kotlinCompileTask's language version as
// kspTask's language version is yet to be configured by configurator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,36 @@ class PlaygroundIT {

project.restore("workload/build.gradle.kts")
}

@Test
fun testProjectExtensionCompilerOptions() {
val properties = File(project.root, "gradle.properties")
properties.writeText(
properties.readText().replace(
"kotlin.jvm.target.validation.mode=warning",
"kotlin.jvm.target.validation.mode=error"
)
)
val buildFile = File(project.root, "workload/build.gradle.kts")
buildFile.appendText(
"""
kotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
}
""".trimIndent()
)
val gradleRunner = GradleRunner.create().withProjectDir(project.root).withGradleVersion("8.0")
gradleRunner.withArguments("clean", "build").buildAndFail().let { result ->
Assert.assertTrue(
result.output.contains(
"'compileJava' task (current target is 11) and 'kspKotlin' " +
"task (current target is 17) jvm target compatibility should be set to the same Java version."
)
)
}
project.restore(buildFile.path)
project.restore(properties.path)
}
}

0 comments on commit 0f4590f

Please sign in to comment.