diff --git a/tapmoc-gradle-plugin/src/kgp/kotlin/tapmoc/internal/KgpImpl.kt b/tapmoc-gradle-plugin/src/kgp/kotlin/tapmoc/internal/KgpImpl.kt index 7360727..1b7c706 100644 --- a/tapmoc-gradle-plugin/src/kgp/kotlin/tapmoc/internal/KgpImpl.kt +++ b/tapmoc-gradle-plugin/src/kgp/kotlin/tapmoc/internal/KgpImpl.kt @@ -4,6 +4,7 @@ import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.NamedDomainObjectSet import org.gradle.api.Project import org.gradle.api.artifacts.dsl.DependencyHandler +import org.gradle.api.provider.Property import org.gradle.api.provider.ProviderFactory import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension @@ -49,7 +50,7 @@ private class KgpImpl(private val dependencyHandler: DependencyHandler, extensio * jvmTarget needs to be set as well, or we get an error such as * e: '-Xjdk-release=11' option conflicts with '-jvm-target 17'. Please remove the '-jvm-target' option */ - this.jvmTarget.set(version.toJvmTarget()) + jvmTarget.setAndDisallowChanges(version.toJvmTarget()) } } } @@ -60,14 +61,14 @@ private class KgpImpl(private val dependencyHandler: DependencyHandler, extensio when (kotlinProjectExtension) { is KotlinAndroidProjectExtension -> { kotlinProjectExtension.compilerOptions { - apiVersion.set(kotlinVersion) - languageVersion.set(kotlinVersion) + apiVersion.setAndDisallowChanges(kotlinVersion) + languageVersion.setAndDisallowChanges(kotlinVersion) } } is KotlinJvmProjectExtension -> { kotlinProjectExtension.compilerOptions { - apiVersion.set(kotlinVersion) - languageVersion.set(kotlinVersion) + apiVersion.setAndDisallowChanges(kotlinVersion) + languageVersion.setAndDisallowChanges(kotlinVersion) } } is KotlinMultiplatformExtension -> { @@ -80,8 +81,8 @@ private class KgpImpl(private val dependencyHandler: DependencyHandler, extensio * * See https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-dsl-reference.html#compiler-options */ - apiVersion.set(kotlinVersion) - languageVersion.set(kotlinVersion) + apiVersion.setAndDisallowChanges(kotlinVersion) + languageVersion.setAndDisallowChanges(kotlinVersion) } } else { /** @@ -89,8 +90,8 @@ private class KgpImpl(private val dependencyHandler: DependencyHandler, extensio * common source sets, but the final binaries should still target the correct version. */ kotlinProjectExtension.forEachCompilerOptions { - apiVersion.set(kotlinVersion) - languageVersion.set(kotlinVersion) + apiVersion.setAndDisallowChanges(kotlinVersion) + languageVersion.setAndDisallowChanges(kotlinVersion) } } } @@ -230,3 +231,8 @@ internal fun Project.onKgp(block: (Kgp) -> Unit) { } } } + +internal fun Property.setAndDisallowChanges(value: T) { + set(value) + disallowChanges() +} diff --git a/tapmoc-gradle-plugin/src/main/kotlin/tapmoc/compatibility.kt b/tapmoc-gradle-plugin/src/main/kotlin/tapmoc/compatibility.kt index 010fe73..a334f48 100644 --- a/tapmoc-gradle-plugin/src/main/kotlin/tapmoc/compatibility.kt +++ b/tapmoc-gradle-plugin/src/main/kotlin/tapmoc/compatibility.kt @@ -1,10 +1,11 @@ package tapmoc -import tapmoc.internal.onAgp import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.tasks.compile.JavaCompile +import tapmoc.internal.onAgp import tapmoc.internal.onKgp +import tapmoc.internal.setAndDisallowChanges fun Project.configureJavaCompatibility( javaVersion: Int, @@ -14,7 +15,7 @@ fun Project.configureJavaCompatibility( */ tasks.withType(JavaCompile::class.java).configureEach { if (!isAndroidJavaCompileTask(it.name)) { - it.options.release.set(javaVersion) + it.options.release.setAndDisallowChanges(javaVersion) } }