Assemble protobuf-lite with gradle, and use it in kotlin-reflect.

This commit is contained in:
Ilya Gorbunov
2017-03-27 07:01:49 +03:00
parent d1d62d557d
commit 026a76e98c
3 changed files with 106 additions and 13 deletions
@@ -0,0 +1,97 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
}
}
apply plugin: 'com.github.johnrengelman.shadow'
def protobufVersion = "2.6.1"
def outputJarPath = "$buildDir/libs/${archivesBaseName}-${protobufVersion}.jar"
version = protobufVersion
configurations {
protobuf
protobufSrc
}
dependencies {
protobuf "com.google.protobuf:protobuf-java:$protobufVersion"
protobufSrc "com.google.protobuf:protobuf-java:$protobufVersion:sources"
}
task shadowJar(type: ShadowJar) {
classifier = "shadow"
version = null
configurations = [project.configurations.protobuf]
relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf" ) {
exclude("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")
}
}
createScriptTask(project, "buildLiteJar") {
dependsOn shadowJar
def inputJar = shadowJar.archivePath
inputs.file(inputJar)
outputs.file(outputJarPath)
args += [
"${rootDir}/../generators/infrastructure/build-protobuf-lite.kts",
inputJar,
outputJarPath
]
}
def artifactJar = [file: file(outputJarPath), builtBy: buildLiteJar]
task sourcesJar(type: Jar) {
inputs.file configurations.protobufSrc
def tmpSrcDir = "${buildDir}/src"
doFirst {
copy {
from (zipTree(configurations.protobufSrc.singleFile))
into tmpSrcDir
}
ant.replaceregexp(
match: 'com\\.google\\.protobuf',
replace: 'org.jetbrains.kotlin.protobuf',
flags: 'g'
) {
fileset(dir: tmpSrcDir) {
include(name: "**/*.java")
}
}
}
classifier 'sources'
from ("${tmpSrcDir}/com/google/protobuf") {
into 'org/jetbrains/kotlin/protobuf'
}
doLast {
delete(tmpSrcDir)
}
}
artifacts {
it."default"(artifactJar)
archives(artifactJar)
archives(sourcesJar)
}
assemble {
dependsOn configurations.archives
}