Set default kotlin api/lang version based on plugin
parent
3e094b0e7b
commit
de8749b264
|
@ -25,18 +25,18 @@ plugins {
|
|||
|
||||
id("com.gradle.plugin-publish") version "0.12.0"
|
||||
|
||||
id("com.dorkbox.Licensing") version "2.2"
|
||||
id("com.dorkbox.Licensing") version "2.4"
|
||||
id("com.dorkbox.VersionUpdate") version "2.0"
|
||||
id("com.dorkbox.GradleUtils") version "1.9"
|
||||
|
||||
kotlin("jvm") version "1.3.72"
|
||||
kotlin("jvm") version "1.4.0"
|
||||
}
|
||||
|
||||
object Extras {
|
||||
// set for the project
|
||||
const val description = "Gradle Plugin to manage various Gradle tasks, such as updating gradle and dependencies"
|
||||
const val group = "com.dorkbox"
|
||||
const val version = "1.10"
|
||||
const val version = "1.11"
|
||||
|
||||
// set as project.ext
|
||||
const val name = "Gradle Utils"
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.gradle.api.plugins.JavaPluginConvention
|
|||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
@ -242,6 +243,18 @@ open class StaticMethodsAndTools(private val project: Project) {
|
|||
fun compileConfiguration(javaVersion: JavaVersion, kotlinActions: (KotlinJvmOptions) -> Unit = {}) {
|
||||
val javaVer = javaVersion.toString()
|
||||
|
||||
val kotlinVer: String = try {
|
||||
val kot = project.plugins.findPlugin("org.jetbrains.kotlin.jvm") as org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper?
|
||||
val version = kot?.kotlinPluginVersion ?: "1.3.0"
|
||||
|
||||
// we ONLY care about the major.minor
|
||||
val secondDot = version.indexOf('.', version.indexOf('.')+1)
|
||||
version.substring(0, secondDot)
|
||||
} catch (e: Exception) {
|
||||
// in case we cannot parse it from the plugin, provide a reasonable default
|
||||
"1.3"
|
||||
}
|
||||
|
||||
project.allprojects.forEach { project ->
|
||||
project.tasks.withType(JavaCompile::class.java) { task ->
|
||||
task.doFirst {
|
||||
|
@ -274,9 +287,9 @@ open class StaticMethodsAndTools(private val project: Project) {
|
|||
|
||||
task.kotlinOptions.jvmTarget = javaVer
|
||||
|
||||
// default is 1.3
|
||||
task.kotlinOptions.apiVersion = "1.3"
|
||||
task.kotlinOptions.languageVersion = "1.3"
|
||||
// default is whatever the version is that we are running, or 1.3 if we cannot figure it out
|
||||
task.kotlinOptions.apiVersion = kotlinVer
|
||||
task.kotlinOptions.languageVersion = kotlinVer
|
||||
|
||||
// see: https://kotlinlang.org/docs/reference/using-gradle.html
|
||||
kotlinActions(task.kotlinOptions)
|
||||
|
|
Loading…
Reference in New Issue