Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions tapmoc-gradle-plugin/src/kgp/kotlin/tapmoc/internal/KgpImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
}
}
Expand All @@ -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 -> {
Expand All @@ -80,17 +81,17 @@ 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 {
/**
* Kotlin <2.0: not sure how we do the same thing. The IDE won't be able to get the proper information in
* 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)
}
}
}
Expand Down Expand Up @@ -230,3 +231,8 @@ internal fun Project.onKgp(block: (Kgp) -> Unit) {
}
}
}

internal fun <T: Any> Property<T>.setAndDisallowChanges(value: T) {
set(value)
disallowChanges()
}
5 changes: 3 additions & 2 deletions tapmoc-gradle-plugin/src/main/kotlin/tapmoc/compatibility.kt
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
}
}

Expand Down
Loading