Skip to content

Commit 2c013a3

Browse files
committed
Convert kotlin.init.gradle to .kts
1 parent 844a9ca commit 2c013a3

File tree

4 files changed

+47
-51
lines changed

4 files changed

+47
-51
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ val publish by tasks.creating(GradleBuild::class) {
6565
outputs.dir(outputDir)
6666

6767
doFirst {
68-
// TODO remove once kotlin.init.gradle is rewritten in Kotlin
68+
// TODO remove after finding a way to apply consts.gradle.kts to kotlin.init.gradle.kts
6969
// persist 'consts' properties since groovy files can't apply .kts scripts
7070
val storeableConsts = Properties()
7171
for ((key, value) in consts) {

consts.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ val consts: Properties by extra(object : Properties() {
4747

4848
val kotlinDir by superRootDir.resolve("kotlin")
4949
val outputDir by superRootDir.resolve("build/out")
50-
val initFile by superRootDir.resolve("kotlin.init.gradle")
50+
val initFile by superRootDir.resolve("kotlin.init.gradle.kts")
5151

5252
val injectedParent by "__injected"
5353
val injectedDir by superRootDir.resolve(injectedParent)

kotlin.init.gradle

Lines changed: 0 additions & 49 deletions
This file was deleted.

kotlin.init.gradle.kts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.io.FileInputStream
2+
import java.util.Properties
3+
4+
log("ENABLED")
5+
6+
val consts = file("build/consts.xml").let { file -> Properties().apply { loadFromXML(FileInputStream(file)) } }
7+
8+
val kotlinVersion = consts["kotlinVersion"] as String
9+
val injectedDir = consts["injectedDir"]!!.let(::file)
10+
val injectedModuleNames = consts["injectedModuleNames"].let { (it as String).split(":").toList() }
11+
12+
val jdk6 = 16
13+
val jdk8 = 18
14+
15+
gradle.settingsEvaluated {
16+
val projectNames = injectedModuleNames.map { addExtraProject(injectedDir, it) }
17+
gradle.rootProject {
18+
extra["deployVersion"] = kotlinVersion
19+
log("set root extra deployVersion=$kotlinVersion")
20+
21+
(jdk6..jdk8).reversed().fold(System.getenv("JAVA_HOME")) { javaHome, jdk ->
22+
val jdkEnv = "JDK_$jdk"
23+
val jdkHome = findProperty(jdkEnv) as? String ?: System.getenv(jdkEnv) ?: javaHome
24+
extra[jdkEnv] = jdkHome
25+
log("set root extra $jdkEnv=$jdkHome")
26+
jdkHome
27+
}
28+
29+
project(projectNames.first()).afterEvaluate {
30+
this@rootProject.defaultTasks = defaultTasks
31+
log("set default tasks on root project from project '$path': $defaultTasks")
32+
}
33+
}
34+
}
35+
36+
fun log(message: String) = println("Settings override: $message")
37+
38+
fun Settings.addExtraProject(parentDir: File, dirName: String): String {
39+
val projectDir = parentDir.resolve(dirName)
40+
val logicalPath = ":${parentDir.name}:$dirName"
41+
include(logicalPath)
42+
project(logicalPath).projectDir = projectDir
43+
log("injected project '$logicalPath' from '$projectDir'")
44+
return logicalPath
45+
}

0 commit comments

Comments
 (0)