Skip to content

Commit 7c85cee

Browse files
authored
Simplify build file (#300)
* Use toolchains to set JDK version for compilation * Use standard methods to apply compiler options to compilations * Remove API/language version override checks These aren't necessary since kotlin-dsl is not applied to the project anymore. There is nothing else that is setting the API or language version. * Set JVM target version with jvmTarget * Remove redundant suppression
1 parent 4c10824 commit 7c85cee

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

build.gradle.kts

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.jetbrains.gradle.ext.copyright
55
import org.jetbrains.gradle.ext.settings
66
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
77
import kotlin.math.min
8+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
89

910
plugins {
1011
id("org.jetbrains.kotlin.jvm") version "1.8.22"
@@ -145,7 +146,6 @@ val e2eTest: SourceSet by sourceSets.creating {
145146
runtimeClasspath += sourceSets["main"].output
146147
}
147148

148-
@Suppress("UnstableApiUsage") // `configurations` container is incubating
149149
configurations {
150150
compatTestCompileClasspath {
151151
extendsFrom(testCompileClasspath.get())
@@ -170,44 +170,28 @@ sourceSets {
170170
}
171171
}
172172

173-
kotlin.target.compilations.configureEach {
174-
// Supporting Gradle 6.2+ needs to use Kotlin 1.3.
175-
// See https://docs.gradle.org/current/userguide/compatibility.html
176-
// For future maintainer: Kotlin 1.9.0 dropped support for Kotlin 1.3, it'll only support 1.4+.
177-
// This means Gradle 7.0 will be the lowest supportable version for plugins.
178-
val usedKotlinVersion = @Suppress("DEPRECATION") KotlinVersion.KOTLIN_1_3
173+
tasks {
174+
withType<KotlinJvmCompile>().configureEach {
175+
compilerOptions {
176+
// Gradle fully supports running on Java 8: https://docs.gradle.org/current/userguide/compatibility.html,
177+
// so we should allow users to do that too.
178+
jvmTarget = JvmTarget.JVM_1_8
179179

180-
compilerOptions.configure {
181-
// Gradle fully supports running on Java 8: https://docs.gradle.org/current/userguide/compatibility.html,
182-
// so we should allow users to do that too.
183-
jvmTarget = JvmTarget.fromTarget(JavaVersion.VERSION_1_8.toString())
180+
// Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin".
181+
freeCompilerArgs.add("-Xsuppress-version-warnings")
184182

185-
// Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin".
186-
freeCompilerArgs.add("-Xsuppress-version-warnings")
187-
}
188-
compileTaskProvider.configure {
189-
// These two (api & lang) needs to be here instead of in compilations.compilerOptions.configure { },
190-
// to prevent KotlinDslCompilerPlugins overriding to Kotlin 1.8.
191-
compilerOptions.apiVersion = usedKotlinVersion
192-
// Theoretically we could use newer language version here,
193-
// but sadly the @kotlin.Metadata created on the classes would be incompatible with older consumers.
194-
compilerOptions.languageVersion = usedKotlinVersion
183+
// Supporting Gradle 6.2+ needs to use Kotlin 1.3.
184+
// See https://docs.gradle.org/current/userguide/compatibility.html
185+
// For future maintainer: Kotlin 1.9.0 dropped support for Kotlin 1.3, it'll only support 1.4+.
186+
// This means Gradle 7.0 will be the lowest supportable version for plugins.
187+
val usedKotlinVersion = @Suppress("DEPRECATION") KotlinVersion.KOTLIN_1_3
195188

196-
// Validate that we're using the right version.
197-
doFirst {
198-
val api = compilerOptions.apiVersion.get()
199-
val language = compilerOptions.languageVersion.get()
200-
if (api != usedKotlinVersion || language != usedKotlinVersion) {
201-
TODO(
202-
"There's mismatch between configured and actual versions:\n" +
203-
"apiVersion=${api}, languageVersion=${language}, configured=${usedKotlinVersion}."
204-
)
205-
}
189+
apiVersion = usedKotlinVersion
190+
// Theoretically we could use newer language version here,
191+
// but sadly the @kotlin.Metadata created on the classes would be incompatible with older consumers.
192+
languageVersion = usedKotlinVersion
206193
}
207194
}
208-
}
209-
210-
tasks {
211195
shadowJar {
212196
exclude("META-INF/maven/**", "META-INF/proguard/**", "META-INF/*.kotlin_module")
213197
manifest {

0 commit comments

Comments
 (0)