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