Create task to run kotlin scripts and use it to strip metadata.
This commit is contained in:
+29
-1
@@ -2,12 +2,13 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.1-SNAPSHOT"
|
||||
ext.kotlin_language_version = "1.1"
|
||||
ext.kotlin_gradle_plugin_version = "1.1.1"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.1"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_gradle_plugin_version}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +30,15 @@ subprojects {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
configurations {
|
||||
scriptCompile
|
||||
scriptRuntime.extendsFrom(scriptCompile)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
scriptCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlin_gradle_plugin_version}"
|
||||
}
|
||||
|
||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile) {
|
||||
compilerJarFile = bootstrapCompilerFile
|
||||
}
|
||||
@@ -125,3 +135,21 @@ def createPreprocessorTask(Project project, def name, def sourceDir, def targetD
|
||||
args = [sourceDir, targetDir, profile]
|
||||
}
|
||||
}
|
||||
|
||||
static def createScriptTask(Project project, def name, Closure<JavaExec> configureClosure = null) {
|
||||
JavaExec task = project.tasks.create(name, JavaExec)
|
||||
return project.configure(task) {
|
||||
classpath = project.configurations.scriptCompile
|
||||
main = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
|
||||
args = [
|
||||
"-script",
|
||||
"-version",
|
||||
"-no-stdlib",
|
||||
"-cp", project.configurations.scriptRuntime.asPath]
|
||||
|
||||
if (configureClosure != null) {
|
||||
configureClosure.delegate = it
|
||||
configureClosure.call()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ sourceSets {
|
||||
srcDir "${core}/reflection.jvm/src"
|
||||
}
|
||||
}
|
||||
|
||||
stripAnnotations
|
||||
}
|
||||
|
||||
configurations {
|
||||
@@ -48,9 +46,6 @@ dependencies {
|
||||
shadowes files("${depDir}/protobuf-2.6.1-lite.jar")
|
||||
|
||||
compile project(':kotlin-stdlib')
|
||||
|
||||
stripAnnotationsCompile 'org.ow2.asm:asm-debug-all:5.0.4'
|
||||
stripAnnotationsCompile project(':kotlin-stdlib')
|
||||
}
|
||||
|
||||
task copyAnnotations(type: Sync) {
|
||||
@@ -95,30 +90,33 @@ task reflectShadowJar(type: ShadowJar) {
|
||||
relocate 'javax.inject', 'kotlin.reflect.jvm.internal.impl.javax.inject'
|
||||
}
|
||||
|
||||
// TODO
|
||||
compileStripAnnotationsKotlin {
|
||||
createScriptTask(project, "stripMetadata") {
|
||||
dependsOn reflectShadowJar
|
||||
source "${rootDir}/../generators/infrastructure/strip-kotlin-annotations.kts"
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = [
|
||||
"-version",
|
||||
"-script",
|
||||
"${rootDir}/../generators/infrastructure/strip-kotlin-annotations.kts",
|
||||
"kotlin/Metadata",
|
||||
"kotlin/reflect/jvm/internal/impl/.*",
|
||||
"${buildDir}/libs/kotlin-reflect-shadow.jar",
|
||||
"${buildDir}/libs/kotlin-reflect-stripped.jar"
|
||||
]
|
||||
}
|
||||
def inputJar = reflectShadowJar.archivePath
|
||||
def outputJar = "${buildDir}/libs/kotlin-reflect-stripped.jar"
|
||||
inputs.file(inputJar)
|
||||
outputs.file(outputJar)
|
||||
args += [
|
||||
"${rootDir}/../generators/infrastructure/strip-kotlin-annotations.kts",
|
||||
"kotlin/Metadata",
|
||||
"kotlin/reflect/jvm/internal/impl/.*",
|
||||
inputJar,
|
||||
outputJar
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def mainArchiveName = "${archivesBaseName}-${project.version}.jar"
|
||||
def outputJarPath = "${buildDir}/libs/${mainArchiveName}"
|
||||
def rtJar = ['jre/lib/rt.jar', '../Classes/classes.jar'].collect { new File(JDK_16, it) }.find { it.isFile() }
|
||||
|
||||
task proguard(type: proguard.gradle.ProGuardTask) {
|
||||
dependsOn reflectShadowJar
|
||||
injars "${buildDir}/libs/kotlin-reflect-shadow.jar"
|
||||
outjars "${buildDir}/libs/${mainArchiveName}"
|
||||
dependsOn stripMetadata
|
||||
inputs.files(stripMetadata.outputs.files)
|
||||
outputs.file(outputJarPath)
|
||||
|
||||
injars stripMetadata.outputs.files
|
||||
outjars outputJarPath
|
||||
|
||||
libraryjars configurations.proguardDeps.files
|
||||
libraryjars rtJar
|
||||
@@ -163,11 +161,11 @@ task relocatedSourcesJar(type: Jar) {
|
||||
}
|
||||
|
||||
artifacts {
|
||||
it.default(file("${buildDir}/libs/${mainArchiveName}")) {
|
||||
it.default(file(outputJarPath)) {
|
||||
builtBy proguard
|
||||
}
|
||||
|
||||
archives(file("${buildDir}/libs/${mainArchiveName}")) {
|
||||
archives(file(outputJarPath)) {
|
||||
name archivesBaseName
|
||||
builtBy proguard
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user