Set proper jvmTarget for projects

This commit is contained in:
Ilya Chernikov
2017-08-22 15:04:58 +02:00
parent deda50dbbb
commit 27968c8e13
33 changed files with 106 additions and 4 deletions
+36 -1
View File
@@ -1,4 +1,6 @@
import org.gradle.api.Project
import java.util.*
import java.io.File
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.java
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -165,8 +167,14 @@ fun Project.allprojectsRecursive(body: Project.() -> Unit) {
this.subprojects { allprojectsRecursive(body) }
}
val defaultJvmTarget = "1.8"
val defaultJavaHome = jdkPath(defaultJvmTarget!!)
allprojects {
jvmTarget = defaultJvmTarget
javaHome = defaultJavaHome
buildDir = File(commonBuildDir, project.name)
repositories {
@@ -176,10 +184,11 @@ allprojects {
mavenCentral()
jcenter()
}
configureJvmProject(javaHome!!, jvmTarget!!)
tasks.withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs = listOf("-Xallow-kotlin-package", "-module-name", project.name)
kotlinOptions.jvmTarget = "1.8"
// kotlinOptions.jvmTarget = "1.8"
}
tasks.withType<Kotlin2JsCompile> {
@@ -197,6 +206,13 @@ allprojects {
tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
afterEvaluate {
logger.info("configuring project $name to compile to the target jvm version $jvmTarget using jdk: $javaHome")
if (javaHome != defaultJavaHome || jvmTarget != defaultJvmTarget) {
configureJvmProject(javaHome!!, jvmTarget!!)
}
}
}
task<Copy>("dist") {
@@ -288,3 +304,22 @@ fun jdkPath(version: String): String {
val varName = "JDK_${version.replace(".", "")}"
return System.getenv(varName) ?: throw GradleException ("Please set environment variable $varName to point to JDK $version installation")
}
fun Project.configureJvmProject(javaHome: String, javaVersion: String) {
tasks.withType<JavaCompile> {
options.forkOptions.javaHome = file(javaHome)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jdkHome = javaHome
kotlinOptions.jvmTarget = javaVersion
doFirst {
System.setProperty("kotlin.colors.enabled", "false")
}
}
tasks.withType<Test> {
executable = File(javaHome, "bin/java").canonicalPath
}
}
+8 -2
View File
@@ -65,7 +65,13 @@ fun Project.getResourceFiles(): SourceDirectorySet? = withJavaPlugin {
the<JavaPluginConvention>().sourceSets.getByName("main").resources
}
fun File(root: File, vararg children: String): File = children.fold(root, { f, c -> File(f, c) })
fun File(root: String, vararg children: String): File = children.fold(File(root), { f, c -> File(f, c) })
var Project.jvmTarget: String?
get() = extra.takeIf { it.has("jvmTarget") }?.get("jvmTarget") as? String
set(v) { extra["jvmTarget"] = v }
var Project.javaHome: String?
get() = extra.takeIf { it.has("javaHome") }?.get("javaHome") as? String
set(v) { extra["javaHome"] = v }
+3 -1
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:cli"))
@@ -21,7 +23,7 @@ dependencies {
}
sourceSets {
"main" { java.srcDirs() }
"main" { projectDefault() }
"test" { projectDefault() }
}
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":core"))
compile(project(":compiler:util"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:backend-common"))
+2
View File
@@ -3,6 +3,8 @@ import java.io.File
apply { plugin("kotlin") }
jvmTarget = "1.6"
val compilerModules: Array<String> by rootProject.extra
val otherCompilerModules = compilerModules.filter { it != path }
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:cli-common"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":core:util.runtime"))
compile(project(":compiler:frontend"))
+2
View File
@@ -3,6 +3,8 @@ description = "Kotlin Runner"
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
val compile by configurations
compile(project(":kotlin-stdlib"))
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":kotlin-build-common"))
compile(project(":compiler:cli-common"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":core:util.runtime"))
compile(commonDep("javax.inject"))
@@ -3,6 +3,8 @@ description = "Kotlin Daemon Client"
apply { plugin("kotlin") }
jvmTarget = "1.6"
val nativePlatformUberjar = preloadedDeps("native-platform-uberjar")
dependencies {
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":core"))
compile(project(":compiler:util"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":core"))
compile(project(":compiler:util"))
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":core"))
compile(project(":compiler:util"))
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":core"))
compile(project(":compiler:util"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":compiler:backend"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(ideaSdkCoreDeps("intellij-core"))
compile(project(":compiler:util"))
+2
View File
@@ -3,6 +3,8 @@ description = "Kotlin Preloader"
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
val compile by configurations
compile(ideaSdkDeps("asm-all"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":core"))
+2
View File
@@ -1,6 +1,8 @@
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
compile(project(":compiler:util"))
compile(project(":core"))
+2
View File
@@ -4,6 +4,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
val compile by configurations
compile(project(":core:builtins"))
+2
View File
@@ -7,6 +7,8 @@ import java.io.File
apply { plugin("kotlin") }
jvmTarget = "1.6"
val builtinsSrc = File(rootDir, "core", "builtins", "src")
val builtinsNative = File(rootDir, "core", "builtins", "native")
// TODO: rewrite dependent projects on using build results instead of the fixed location
+2
View File
@@ -19,6 +19,8 @@ apply {
plugin("com.github.johnrengelman.shadow")
}
jvmTarget = "1.6"
dependencies {
val compile by configurations
compile(project(":core:builtins"))
+2
View File
@@ -3,6 +3,8 @@ import org.gradle.jvm.tasks.Jar
apply { plugin("kotlin") }
jvmTarget = "1.6"
dependencies {
val compile by configurations
compile(project(":core:builtins"))
+2
View File
@@ -4,6 +4,8 @@ apply {
plugin("kotlin")
}
jvmTarget = "1.6"
dependencies {
compile(project(":core:builtins"))
compile(project(":kotlin-stdlib"))
+3
View File
@@ -43,6 +43,9 @@ ext.configureJvmProject = { Project project ->
ext.configureJvm6Project = { Project project ->
project.configure(project) {
project.ext.jvmTarget = "1.6"
project.ext.javaHome = JDK_16
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.kotlin
+1
View File
@@ -4,6 +4,7 @@ apply plugin: 'kotlin'
configureJvm6Project(project)
configurePublishing(project)
ext.javaHome = JDK_17
dependencies {
compile project(':kotlin-stdlib')
+1
View File
@@ -4,6 +4,7 @@ apply plugin: 'kotlin'
configureJvm6Project(project)
configurePublishing(project)
ext.javaHome = JDK_18
dependencies {
compile project(':kotlin-stdlib')