build.gradle.kts 4.4 KB
Newer Older
1 2 3 4 5 6

import java.io.File
import proguard.gradle.ProGuardTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.file.DuplicatesStrategy

7 8
description = "Kotlin Compiler"

9 10 11 12 13 14
buildscript {
    repositories {
        jcenter()
    }

    dependencies {
15
        classpath("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}")
16 17 18 19
        classpath("net.sf.proguard:proguard-gradle:5.3.1")
    }
}

20
plugins {
21
    `java`
22
}
23 24 25 26

// Set to false to disable proguard run on kotlin-compiler.jar. Speeds up the build
val shrink = true
val compilerManifestClassPath =
27
        "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar"
28

29 30 31 32 33 34
val fatJarContents by configurations.creating
val fatSourcesJarContents by configurations.creating
val proguardLibraryJars by configurations.creating
val fatJar by configurations.creating
val compilerJar by configurations.creating
val archives by configurations
35
val compile by configurations
36

37
val compilerBaseName = name
38 39 40

val outputJar = File(buildDir, "libs", "$compilerBaseName.jar")

41 42
val compilerModules: Array<String> by rootProject.extra

43 44 45
val ideaCoreSdkJars: Array<String> by rootProject.extra
val coreSdkJarsSimple = ideaCoreSdkJars.filterNot { it == "jdom" || it == "log4j" }.toTypedArray()

46 47 48 49 50
compilerModules.forEach { evaluationDependsOn(it) }

val compiledModulesSources = compilerModules.map {
    project(it).the<JavaPluginConvention>().sourceSets.getByName("main").allSource
}
51 52

dependencies {
53 54 55 56 57 58 59 60
    compilerModules.forEach {
        fatJarContents(project(it)) { isTransitive = false }
    }
    compiledModulesSources.forEach {
        fatSourcesJarContents(it)
    }

    fatJarContents(project(":core:builtins", configuration = "builtins"))
61 62
    fatJarContents(ideaSdkCoreDeps(*coreSdkJarsSimple))
    fatJarContents(ideaSdkDeps("jna-platform"))
63 64
    fatJarContents(commonDep("javax.inject"))
    fatJarContents(commonDep("org.jline", "jline"))
I
Ilya Chernikov 已提交
65
    fatJarContents(commonDep("org.fusesource.jansi", "jansi"))
66 67 68 69
    fatJarContents(protobufFull())
    fatJarContents(commonDep("com.google.code.findbugs", "jsr305"))
    fatJarContents(commonDep("io.javaslang", "javaslang"))
    fatJarContents(preloadedDeps("json-org"))
70
    fatJarContents(preloadedDeps("kotlinx-coroutines-core"))
71 72 73

    proguardLibraryJars(files(firstFromJavaHomeThatExists("lib/rt.jar", "../Classes/classes.jar"),
            firstFromJavaHomeThatExists("lib/jsse.jar", "../Classes/jsse.jar"),
74
            toolsJar()))
75 76 77
    proguardLibraryJars(projectDist(":kotlin-stdlib"))
    proguardLibraryJars(projectDist(":kotlin-script-runtime"))
    proguardLibraryJars(projectDist(":kotlin-reflect"))
78 79 80 81

    compile(project(":kotlin-stdlib"))
    compile(project(":kotlin-script-runtime"))
    compile(project(":kotlin-reflect"))
82 83
}

84 85
val packCompiler by task<ShadowJar> {
    configurations = listOf(fatJar)
86 87 88
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    destinationDir = File(buildDir, "libs")
    dependsOn(protobufFullTask)
89

90
    setupPublicJar("before-proguard")
91
    from(fatJarContents)
92 93 94
    ideaSdkDeps("jps-model.jar", subdir = "jps").forEach { from(zipTree(it)) { exclude("META-INF/services/**") } }
    ideaSdkDeps("oromatcher").forEach { from(zipTree(it)) { exclude("META-INF/jb/** META-INF/LICENSE") } }
    ideaSdkCoreDeps("jdom", "log4j").forEach { from(zipTree(it)) { exclude("META-INF/jb/** META-INF/LICENSE") } }
95 96 97 98 99

    manifest.attributes.put("Class-Path", compilerManifestClassPath)
    manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
}

100 101
val proguard by task<ProGuardTask> {
    dependsOn(packCompiler)
102 103
    configuration("$rootDir/compiler/compiler.pro")

104 105 106
    val outputJar = File(buildDir, "libs", "$compilerBaseName-after-proguard.jar")

    inputs.files(packCompiler.outputs.files.singleFile)
107 108 109 110
    outputs.file(outputJar)

    // TODO: remove after dropping compatibility with ant build
    doFirst {
111
        System.setProperty("kotlin-compiler-jar-before-shrink", packCompiler.outputs.files.singleFile.canonicalPath)
112 113 114
        System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath)
    }

115
    libraryjars(proguardLibraryJars)
116 117 118
    printconfiguration("$buildDir/compiler.pro.dump")
}

119 120
noDefaultJar()

121 122
cleanArtifacts()

123 124 125
dist(targetName = compilerBaseName + ".jar",
     fromTask = if (shrink) proguard
                else packCompiler)
126

127 128
runtimeJarArtifactBy(proguard, proguard.outputs.files.singleFile) {
    name = compilerBaseName
129 130
    classifier = ""
}
131 132 133 134
sourcesJar {
    from(fatSourcesJarContents)
}
javadocJar()
135

136
publish()
137