Make withJava() safe to call repeatedlt on same target

This commit is contained in:
Sergey Igushkin
2019-05-29 01:05:43 +03:00
parent 9a4596eaba
commit 25371734e8
2 changed files with 6 additions and 1 deletions
@@ -295,7 +295,9 @@ class NewMultiplatformIT : BaseGradleIT() {
gradleBuildScript().modify {
if (testJavaSupportInJvmTargets) {
it + "\nkotlin.jvm(\"jvm6\").${KotlinJvmTarget::withJava.name}()"
it + "\nkotlin.jvm(\"jvm6\") { " +
"${KotlinJvmTarget::withJava.name.plus("();").repeat(2)} " + // also check that the function is idempotent
"}"
} else {
it.replace("presets.jvm", "presets.jvmWithJava").replace("jvm(", "targetFromPreset(presets.jvmWithJava, ")
}.plus(
@@ -31,6 +31,9 @@ class KotlinJvmTarget(
@Suppress("unused") // user DSL
fun withJava() {
if (withJavaEnabled)
return
project.multiplatformExtension.targets.find { it is KotlinJvmTarget && it.withJavaEnabled }
?.let { existingJavaTarget ->
throw InvalidUserCodeException(