Build.gradle.kts
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath ("com.android.tools.build:gradle:7.0.2")
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30")
classpath("gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:${Versions.spotbugsGradlePluginVersion}")
classpath("se.bjurr.violations:violations-gradle-plugin:${Versions.violationsVersion}")
}
}
//android {
// compileOptions {
// sourceCompatibility = JavaVersion.VERSION_11
// targetCompatibility = JavaVersion.VERSION_11
// }
//
// kotlinOptions {
// jvmTarget = JavaVersion.VERSION_11.toString()
// }
//}
plugins {
`maven-publish`
`java-gradle-plugin`
`kotlin-dsl`
id ("io.gitlab.arturbosch.detekt") version ("1.18.1")
}
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
compileOnly(gradleApi())
testImplementation(gradleTestKit())
testImplementation("junit:junit:${Versions.jUnitVersion}")
}
val generatedSources = tasks.register<GenerateVersionsFileTask>("generateSources")
ERROR : 'compileJava' task (current target is 11) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
When I uncomment android {} Error : Script compilation errors:
Line 15: android {
^ Unresolved reference: android
Thanks for your time and effort :) Jitendra
You can set java version for java with
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
or alternatively:
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(11))
}
and for kotlin with:
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
}
}
All samples are in gradle kotlin dsl.
@Marian's answer didn't quite help me.
I end up setting the following in the app build.gradle
Android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget=11
}
...
}