Implement Gradle Kotlin DSL build

This commit is contained in:
Ilya Chernikov
2017-08-02 12:26:50 +02:00
parent f5d6e41993
commit 61dfb75e0e
93 changed files with 3737 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
apply {
plugin("kotlin")
}
dependencies {
val compile by configurations
val compileOnly by configurations
val testCompile by configurations
val testCompileOnly by configurations
val testRuntime by configurations
compile(project(":compiler:util"))
compile(project(":compiler:cli"))
compile(project(":compiler.tests-common"))
compile(project(":compiler:frontend"))
compile(project(":compiler:backend"))
testCompile(project(":compiler:incremental-compilation-impl"))
testCompile(project(":core"))
testCompile(project(":compiler:frontend.java"))
testCompile(projectTests(":jps-plugin"))
testCompile(commonDep("junit:junit"))
testCompile(ideaSdkDeps("jps-model.jar", subdir = "jps"))
testCompile(ideaSdkDeps("groovy-all"))
testCompile(ideaSdkDeps("openapi", "idea"))
testCompile(ideaSdkDeps("jps-build-test", subdir = "jps/test"))
testCompile(ideaSdkDeps("jps-builders"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectTestsDefault()
tasks.withType<Test> {
workingDir = rootDir
systemProperty("idea.is.unit.test", "true")
systemProperty("NO_FS_ROOTS_ACCESS_CHECK", "true")
ignoreFailures = true
}
+14
View File
@@ -0,0 +1,14 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":core"))
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
compile(project(":compiler:ir.tree"))
}
configureKotlinProjectSources("backend-common/src", "ir/backend.common/src", sourcesBaseDir = File(rootDir, "compiler"))
configureKotlinProjectNoTests()
+18
View File
@@ -0,0 +1,18 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:backend-common"))
compile(project(":compiler:frontend"))
compile(project(":compiler:frontend.java"))
compile(project(":compiler:ir.tree"))
compile(project(":compiler:ir.psi2ir"))
compile(project(":compiler:serialization"))
}
configureKotlinProjectSources("backend/src", "ir/backend.jvm/src", sourcesBaseDir = File(rootDir, "compiler"))
configureKotlinProjectResourcesDefault()
configureKotlinProjectNoTests()
+227
View File
@@ -0,0 +1,227 @@
import java.io.File
import proguard.gradle.ProGuardTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.internal.plugins.DslObject
import org.gradle.api.publication.maven.internal.deployer.MavenRemoteRepository
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
classpath("net.sf.proguard:proguard-gradle:5.3.1")
}
}
apply { plugin("kotlin") }
plugins {
maven
}
//apply { plugin("maven") }
// Set to false to disable proguard run on kotlin-compiler.jar. Speeds up the build
val shrink = true
val compilerManifestClassPath =
"kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar"
val fatJarContents by configurations.creating
val proguardLibraryJars by configurations.creating
val fatJar by configurations.creating
val compilerJar by configurations.creating
val embeddableCompilerJar by configurations.creating
val compilerBaseName: String by rootProject.extra
val embeddableCompilerBaseName: String by rootProject.extra
val javaHome = File(System.getProperty("java.home"))
val buildLocalRepoPath: File by rootProject.extra
val compilerModules: Array<String> by rootProject.extra
val otherCompilerModules = compilerModules.filter { it != path }
val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin"
val packagesToRelocate =
listOf("com.intellij",
"com.google",
"com.sampullara",
"org.apache",
"org.jdom",
"org.picocontainer",
"jline",
"gnu",
"javax.inject",
"org.fusesource")
fun firstFromJavaHomeThatExists(vararg paths: String): File =
paths.mapNotNull { File(javaHome, it).takeIf { it.exists() } }.firstOrNull()
?: throw GradleException("Cannot find under '$javaHome' neither of: ${paths.joinToString()}")
dependencies {
val compile by configurations
val compileOnly by configurations
val testCompile by configurations
val testCompileOnly by configurations
val testRuntime by configurations
compileOnly(project(":compiler:cli"))
compileOnly(project(":compiler:daemon-common"))
compileOnly(project(":compiler:incremental-compilation-impl"))
compileOnly(project(":build-common"))
compileOnly(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
compileOnly(commonDep("org.fusesource.jansi", "jansi"))
compileOnly(commonDep("jline"))
testCompile(commonDep("junit:junit"))
testCompile(project(":kotlin-test:kotlin-test-jvm"))
testCompile(project(":kotlin-test:kotlin-test-junit"))
testCompile(project(":compiler.tests-common"))
testCompileOnly(project(":compiler:ir.ir2cfg"))
testCompileOnly(project(":compiler:ir.tree")) // used for deepCopyWithSymbols call that is removed by proguard from the compiler TODO: make it more straightforward
testCompile(ideaSdkDeps("openapi", "idea", "util", "asm-all", "commons-httpclient-3.1-patched"))
// deps below are test runtime deps, but made test compile to split compilation and running to reduce mem req
testCompile(project(":kotlin-stdlib"))
testCompile(project(":kotlin-script-runtime"))
testCompile(project(":kotlin-runtime"))
testCompile(project(":kotlin-reflect"))
testCompile(project(":plugins:android-extensions-compiler"))
testCompile(project(":ant"))
otherCompilerModules.forEach {
testCompile(project(it))
fatJarContents(project(it)) { isTransitive = false }
}
testRuntime(ideaSdkCoreDeps("*.jar"))
testRuntime(ideaSdkDeps("*.jar"))
// testRuntime(project(":prepare:compiler", configuration = "default"))
buildVersion()
fatJarContents(project(":core:builtins", configuration = "builtins"))
fatJarContents(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
fatJarContents(ideaSdkDeps("jna-platform", "oromatcher"))
fatJarContents(ideaSdkDeps("jps-model.jar", subdir = "jps"))
fatJarContents(commonDep("javax.inject"))
fatJarContents(commonDep("jline"))
fatJarContents(protobufFull())
fatJarContents(commonDep("com.github.spullara.cli-parser", "cli-parser"))
fatJarContents(commonDep("com.google.code.findbugs", "jsr305"))
fatJarContents(commonDep("io.javaslang", "javaslang"))
fatJarContents(preloadedDeps("json-org"))
proguardLibraryJars(files(firstFromJavaHomeThatExists("lib/rt.jar", "../Classes/classes.jar"),
firstFromJavaHomeThatExists("lib/jsse.jar", "../Classes/jsse.jar"),
firstFromJavaHomeThatExists("../lib/tools.jar", "../Classes/tools.jar")))
proguardLibraryJars(kotlinDep("stdlib"))
proguardLibraryJars(kotlinDep("script-runtime"))
proguardLibraryJars(kotlinDep("reflect"))
proguardLibraryJars(preloadedDeps("kotlinx-coroutines-core"))
// proguardLibraryJars(project(":prepare:runtime", configuration = "default").apply { isTransitive = false })
// proguardLibraryJars(project(":prepare:reflect", configuration = "default").apply { isTransitive = false })
// proguardLibraryJars(project(":core:script.runtime").apply { isTransitive = false })
}
configureKotlinProjectSources(
"compiler/daemon/src",
"compiler/conditional-preprocessor/src",
sourcesBaseDir = rootDir)
configureKotlinProjectResources("idea/src", sourcesBaseDir = rootDir) {
include("META-INF/extensions/common.xml",
"META-INF/extensions/kotlin2jvm.xml",
"META-INF/extensions/kotlin2js.xml")
}
configureKotlinProjectTests("tests")
testsJar {}
tasks.withType<Test> {
dependsOnTaskIfExistsRec("dist", project = rootProject)
dependsOn(":prepare:mock-runtime-for-test:dist")
workingDir = rootDir
systemProperty("idea.is.unit.test", "true")
environment("NO_FS_ROOTS_ACCESS_CHECK", "true")
systemProperty("kotlin.test.script.classpath", the<JavaPluginConvention>().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
jvmArgs("-ea", "-XX:+HeapDumpOnOutOfMemoryError", "-Xmx1200m", "-XX:+UseCodeCacheFlushing", "-XX:ReservedCodeCacheSize=128m", "-Djna.nosys=true")
maxHeapSize = "1200m"
ignoreFailures = true
}
val packCompiler by task<ShadowJar> {
configurations = listOf(fatJar)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
destinationDir = File(buildDir, "libs")
baseName = compilerBaseName
classifier = "before-proguard"
dependsOn(protobufFullTask)
setupRuntimeJar("Kotlin Compiler")
from(getCompiledClasses())
from(fatJarContents)
manifest.attributes.put("Class-Path", compilerManifestClassPath)
manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
}
val proguard by task<ProGuardTask> {
dependsOn(packCompiler)
configuration("$rootDir/compiler/compiler.pro")
val outputJar = File(buildDir, "libs", "$compilerBaseName-after-proguard.jar")
inputs.files(packCompiler.outputs.files.singleFile)
outputs.file(outputJar)
// TODO: remove after dropping compatibility with ant build
doFirst {
System.setProperty("kotlin-compiler-jar-before-shrink", packCompiler.outputs.files.singleFile.canonicalPath)
System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath)
}
libraryjars(proguardLibraryJars)
printconfiguration("$buildDir/compiler.pro.dump")
}
val embeddable by task<ShadowJar> {
destinationDir = File(buildDir, "libs")
baseName = embeddableCompilerBaseName
configurations = listOf(embeddableCompilerJar)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(proguard)
from(proguard)
relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf")
packagesToRelocate.forEach {
relocate(it, "$kotlinEmbeddableRootPackage.$it")
}
relocate("org.fusesource", "$kotlinEmbeddableRootPackage.org.fusesource") {
// TODO: remove "it." after #KT-12848 get addressed
exclude("org.fusesource.jansi.internal.CLibrary")
}
}
dist {
if (shrink) {
from(proguard)
} else {
from(packCompiler)
}
rename(".*", compilerBaseName + ".jar")
}
artifacts.add(compilerJar.name, proguard.outputs.files.singleFile) {
builtBy(proguard)
classifier = ""
name = compilerBaseName
}
artifacts.add(embeddableCompilerJar.name, embeddable.outputs.files.singleFile) {
builtBy(embeddable)
classifier = ""
name = embeddableCompilerBaseName
}
+32
View File
@@ -0,0 +1,32 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:cli-common"))
compile(project(":compiler:frontend"))
compile(project(":compiler:frontend.java"))
compile(project(":compiler:frontend.script"))
compile(project(":compiler:backend-common"))
compile(project(":compiler:backend"))
compile(project(":compiler:light-classes"))
compile(project(":compiler:serialization"))
compile(project(":compiler:plugin-api"))
compile(project(":js:js.translator"))
compile(project(":js:js.serializer"))
compile(project(":js:js.dce"))
compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
compile(commonDep("org.fusesource.jansi", "jansi"))
compile(commonDep("jline"))
compile(files("${System.getProperty("java.home")}/../lib/tools.jar"))
}
configureKotlinProjectSources("compiler/cli/src",
"plugins/annotation-collector/src",
"compiler/builtins-serializer/src",
"compiler/javac-wrapper/src",
sourcesBaseDir = rootDir)
configureKotlinProjectResourcesDefault()
configureKotlinProjectNoTests()
+15
View File
@@ -0,0 +1,15 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":core:util.runtime"))
compile(project(":compiler:frontend"))
compile(project(":compiler:frontend.java"))
compile(project(":compiler:frontend.script"))
compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+26
View File
@@ -0,0 +1,26 @@
import org.gradle.jvm.tasks.Jar
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(kotlinDep("stdlib"))
buildVersion()
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
val jar: Jar by tasks
jar.apply {
setupRuntimeJar("Kotlin Runner")
manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.runner.Main")
manifest.attributes.put("Class-Path", "kotlin-runtime.jar")
archiveName = "kotlin-runner.jar"
}
dist {
from(jar)
}
+17
View File
@@ -0,0 +1,17 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":build-common"))
compile(project(":compiler:cli-common"))
compile(project(":compiler:preloader"))
compile(project(":compiler:frontend.java"))
compile(project(":compiler:daemon-common"))
compile(project(":compiler:daemon-client"))
compile(project(":compiler:util"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+31
View File
@@ -0,0 +1,31 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
val compileOnly by configurations
val testCompile by configurations
val testCompileOnly by configurations
val testRuntime by configurations
compile(project(":core:util.runtime"))
compile(commonDep("javax.inject"))
compile(ideaSdkCoreDeps("intellij-core"))
testCompile(commonDep("junit:junit"))
testCompile(project(":kotlin-test:kotlin-test-jvm"))
testRuntime(ideaSdkCoreDeps("trove4j", "intellij-core"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectTestsDefault()
testsJar {}
tasks.withType<Test> {
dependsOnTaskIfExistsRec("dist", project = rootProject)
dependsOn(":prepare:mock-runtime-for-test:dist")
workingDir = rootDir
systemProperty("idea.is.unit.test", "true")
environment("NO_FS_ROOTS_ACCESS_CHECK", "true")
ignoreFailures = true
}
@@ -0,0 +1,35 @@
import org.gradle.jvm.tasks.Jar
apply { plugin("kotlin") }
val nativePlatformUberjar = "$rootDir/dependencies/native-platform-uberjar.jar"
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:cli-common"))
compile(project(":compiler:daemon-common"))
compile(files(nativePlatformUberjar))
buildVersion()
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
val jar: Jar by tasks
jar.apply {
setupRuntimeJar("Kotlin Daemon Client")
from(zipTree(nativePlatformUberjar))
archiveName = "kotlin-daemon-client.jar"
}
val sourcesJar by task<Jar> {
setupSourceJar("Kotlin Daemon Client")
archiveName = "kotlin-daemon-client-sources.jar"
}
dist {
from(jar)
}
@@ -0,0 +1,14 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":core"))
compile(project(":compiler:util"))
compile(project(":compiler:cli-common"))
compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+14
View File
@@ -0,0 +1,14 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":core"))
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectResourcesDefault()
configureKotlinProjectNoTests()
+14
View File
@@ -0,0 +1,14 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
compile(kotlinDep("reflect"))
compile(preloadedDeps("kotlinx-coroutines-core"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+16
View File
@@ -0,0 +1,16 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":core"))
compile(project(":compiler:util"))
compile(project(":compiler:container"))
compile(project(":compiler:resolution"))
compile(kotlinDep("script-runtime"))
compile(commonDep("io.javaslang","javaslang"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
@@ -0,0 +1,16 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":core"))
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
compile(project(":compiler:frontend.java"))
compile(project(":compiler:cli"))
compile(project(":build-common"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectTestsDefault()
+13
View File
@@ -0,0 +1,13 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
compile(project(":compiler:ir.tree"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+14
View File
@@ -0,0 +1,14 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
compile(project(":compiler:backend-common"))
compile(project(":compiler:ir.tree"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+12
View File
@@ -0,0 +1,12 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+14
View File
@@ -0,0 +1,14 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:backend"))
compile(project(":compiler:frontend"))
compile(project(":compiler:frontend.java"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+13
View File
@@ -0,0 +1,13 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(ideaSdkCoreDeps("intellij-core"))
compile(project(":compiler:util"))
compile(project(":compiler:frontend"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+25
View File
@@ -0,0 +1,25 @@
import org.gradle.jvm.tasks.Jar
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(ideaSdkDeps("asm-all"))
buildVersion()
}
configureKotlinProjectSources("src", "instrumentation/src")
configureKotlinProjectNoTests()
val jar: Jar by tasks
jar.apply {
setupRuntimeJar("Kotlin Preloader")
manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.preloading.Preloader")
archiveName = "kotlin-preloader.jar"
}
dist {
from(jar)
}
+12
View File
@@ -0,0 +1,12 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":core"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+12
View File
@@ -0,0 +1,12 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":core"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
+56
View File
@@ -0,0 +1,56 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
apply { plugin("kotlin") }
dependencies {
val compile by configurations
val compileOnly by configurations
val testCompile by configurations
val testCompileOnly by configurations
val testRuntime by configurations
testCompile(commonDep("junit:junit"))
testCompile(project(":kotlin-test:kotlin-test-jvm"))
testCompile(project(":kotlin-test:kotlin-test-junit"))
testCompile(project(":compiler.tests-common"))
testCompile(project(":core"))
testCompile(project(":compiler:util"))
testCompile(project(":compiler:backend"))
testCompile(project(":compiler:frontend"))
testCompile(project(":compiler:frontend.java"))
testCompile(project(":compiler:cli"))
testCompile(project(":compiler:serialization"))
testCompile(ideaSdkDeps("openapi", "idea", "util", "asm-all"))
// deps below are test runtime deps, but made test compile to split compilation and running to reduce mem req
testCompile(project(":kotlin-stdlib"))
testCompile(project(":kotlin-script-runtime"))
testCompile(project(":kotlin-runtime"))
testCompile(project(":kotlin-reflect"))
testCompile(projectTests(":compiler"))
testRuntime(project(":compiler:preloader"))
testRuntime(ideaSdkCoreDeps("*.jar"))
testRuntime(ideaSdkDeps("*.jar"))
}
configureKotlinProjectSources()
configureKotlinProjectTestsDefault()
tasks.withType<KotlinCompile> {
kotlinOptions.jdkHome = rootProject.extra["JDK_18"]!!.toString()
kotlinOptions.jvmTarget = "1.8"
}
testsJar {}
tasks.withType<Test> {
executable = "${rootProject.extra["JDK_18"]!!}/bin/java"
dependsOnTaskIfExistsRec("dist", project = rootProject)
dependsOn(":prepare:mock-runtime-for-test:dist")
workingDir = rootDir
systemProperty("idea.is.unit.test", "true")
environment("NO_FS_ROOTS_ACCESS_CHECK", "true")
systemProperty("kotlin.test.script.classpath", the<JavaPluginConvention>().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
jvmArgs("-ea", "-XX:+HeapDumpOnOutOfMemoryError", "-Xmx1200m", "-XX:+UseCodeCacheFlushing", "-XX:ReservedCodeCacheSize=128m", "-Djna.nosys=true")
maxHeapSize = "1200m"
ignoreFailures = true
}
+14
View File
@@ -0,0 +1,14 @@
apply { plugin("kotlin") }
dependencies {
val compile by configurations
compile(project(":core"))
compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
compile(ideaSdkDeps("jps-model.jar", subdir = "jps"))
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectResources("resources", sourcesBaseDir = rootDir)
configureKotlinProjectNoTests()