Switch protobuf usages to regular dependency
This commit is contained in:
committed by
Vyacheslav Gerasimov
parent
a952d797f1
commit
4a47fb3ffb
@@ -53,13 +53,14 @@ fun DependencyHandler.projectArchives(name: String): ProjectDependency = project
|
||||
fun DependencyHandler.projectClasses(name: String): ProjectDependency = project(name, configuration = "classes-dirs")
|
||||
|
||||
val protobufLiteProject = ":custom-dependencies:protobuf-lite"
|
||||
val protobufRelocatedProject = ":custom-dependencies:protobuf-relocated"
|
||||
fun DependencyHandler.protobufLite(): ProjectDependency =
|
||||
project(protobufLiteProject, configuration = "default").apply { isTransitive = false }
|
||||
val protobufLiteTask = "$protobufLiteProject:prepare"
|
||||
|
||||
fun DependencyHandler.protobufFull(): ProjectDependency =
|
||||
project(protobufLiteProject, configuration = "relocated").apply { isTransitive = false }
|
||||
val protobufFullTask = "$protobufLiteProject:prepare-relocated-protobuf"
|
||||
project(protobufRelocatedProject, configuration = "default").apply { isTransitive = false }
|
||||
val protobufFullTask = "$protobufLiteProject:prepare"
|
||||
|
||||
fun File.matchMaybeVersionedArtifact(baseName: String) = name.matches(baseName.toMaybeVersionedJarRegex())
|
||||
|
||||
|
||||
@@ -1,53 +1,29 @@
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.util.jar.JarEntry
|
||||
import java.util.jar.JarFile
|
||||
import java.util.zip.ZipOutputStream
|
||||
import org.gradle.language.assembler.tasks.Assemble
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
val relocatedProtobuf by configurations.creating
|
||||
val relocatedProtobufSources by configurations.creating
|
||||
|
||||
dependencies {
|
||||
classpath("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}")
|
||||
}
|
||||
}
|
||||
|
||||
apply { plugin("com.github.johnrengelman.shadow") }
|
||||
|
||||
val mainCfg = configurations.create("default")
|
||||
val relocatedCfg = configurations.create("relocated")
|
||||
val resultsCfg = configurations.create("default")
|
||||
|
||||
val protobufVersion = rootProject.extra["versions.protobuf-java"]
|
||||
val protobufJarPrefix = "protobuf-$protobufVersion"
|
||||
val renamedOutputJarPath = "$buildDir/jars/$protobufJarPrefix-relocated.jar"
|
||||
val outputJarPath = "$buildDir/libs/$protobufJarPrefix-lite.jar"
|
||||
|
||||
artifacts.add(mainCfg.name, File(outputJarPath))
|
||||
artifacts.add(relocatedCfg.name, File(renamedOutputJarPath))
|
||||
|
||||
dependencies {
|
||||
mainCfg("com.google.protobuf:protobuf-java:$protobufVersion")
|
||||
relocatedProtobuf(project(":custom-dependencies:protobuf-relocated", configuration = "default"))
|
||||
relocatedProtobufSources(project(":custom-dependencies:protobuf-relocated", configuration = "sources"))
|
||||
}
|
||||
|
||||
val relocateTask = task<ShadowJar>("prepare-relocated-protobuf") {
|
||||
archiveName = renamedOutputJarPath
|
||||
this.configurations = listOf(relocatedCfg)
|
||||
from(mainCfg.files.find { it.name.startsWith("protobuf-java") }?.canonicalPath)
|
||||
relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf" ) {
|
||||
// TODO: remove "it." after #KT-12848 get addressed
|
||||
exclude("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")
|
||||
}
|
||||
}
|
||||
|
||||
val mainTask = task("prepare") {
|
||||
dependsOn(relocateTask)
|
||||
val inputJar = renamedOutputJarPath
|
||||
task("prepare") {
|
||||
// TODO: find out why it doesn't work without explicit dependsOn
|
||||
dependsOn(":custom-dependencies:protobuf-relocated:prepare")
|
||||
val inputJar = relocatedProtobuf.files.single()
|
||||
inputs.files(inputJar)
|
||||
outputs.file(outputJarPath)
|
||||
doFirst {
|
||||
@@ -112,10 +88,18 @@ val mainTask = task("prepare") {
|
||||
}
|
||||
}
|
||||
}
|
||||
addArtifact("archives", this, outputs.files.singleFile) {
|
||||
classifier = ""
|
||||
}
|
||||
addArtifact(resultsCfg, this, outputs.files.singleFile) {
|
||||
classifier = ""
|
||||
}
|
||||
}
|
||||
|
||||
defaultTasks(mainTask.name)
|
||||
|
||||
tasks.withType<Assemble>() {
|
||||
dependsOn(mainCfg)
|
||||
val clean by task<Delete> {
|
||||
delete(buildDir)
|
||||
}
|
||||
|
||||
artifacts.add("archives", relocatedProtobufSources.files.single()) {
|
||||
classifier = "sources"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}")
|
||||
}
|
||||
}
|
||||
|
||||
val baseProtobuf by configurations.creating
|
||||
val baseProtobufSources by configurations.creating
|
||||
|
||||
val resultsCfg = configurations.create("default")
|
||||
val resultsSourcesCfg = configurations.create("sources")
|
||||
|
||||
val protobufVersion = rootProject.extra["versions.protobuf-java"] as String
|
||||
val protobufJarPrefix = "protobuf-$protobufVersion"
|
||||
|
||||
val renamedSources = "$buildDir/renamedSrc/"
|
||||
val outputJarsPath = "$buildDir/libs"
|
||||
val artifactBaseName = "protobuf-java-relocated"
|
||||
|
||||
dependencies {
|
||||
baseProtobuf("com.google.protobuf:protobuf-java:$protobufVersion")
|
||||
baseProtobufSources("com.google.protobuf:protobuf-java:$protobufVersion:sources")
|
||||
}
|
||||
|
||||
val prepare by task<ShadowJar> {
|
||||
destinationDir = File(outputJarsPath)
|
||||
baseName = artifactBaseName
|
||||
version = protobufVersion
|
||||
classifier = ""
|
||||
from(baseProtobuf.files.find { it.name.startsWith("protobuf-java") }?.canonicalPath)
|
||||
|
||||
relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf" ) {
|
||||
// TODO: remove "it." after #KT-12848 get addressed
|
||||
exclude("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")
|
||||
}
|
||||
addArtifact("archives", this, this)
|
||||
addArtifact(resultsCfg.name, this, this)
|
||||
}
|
||||
|
||||
val relocateSources by task<Copy> {
|
||||
from(zipTree(baseProtobufSources.files.find { it.name.startsWith("protobuf-java") && it.name.endsWith("-sources.jar") }
|
||||
?: throw GradleException("sources jar not found among ${baseProtobufSources.files}")))
|
||||
into(renamedSources)
|
||||
filter { it.replace("com.google.protobuf", "org.jetbrains.kotlin.protobuf") }
|
||||
}
|
||||
|
||||
val prepareSources by task<Jar> {
|
||||
destinationDir = File(outputJarsPath)
|
||||
baseName = artifactBaseName
|
||||
version = protobufVersion
|
||||
classifier = "sources"
|
||||
from(relocateSources)
|
||||
project.addArtifact("archives", this, this)
|
||||
addArtifact(resultsSourcesCfg.name, this, this)
|
||||
}
|
||||
|
||||
val clean by task<Delete> {
|
||||
delete(buildDir)
|
||||
}
|
||||
@@ -63,7 +63,7 @@ val packedJars by configurations.creating
|
||||
val sideJars by configurations.creating
|
||||
|
||||
dependencies {
|
||||
packedJars(preloadedDeps("protobuf-${rootProject.extra["versions.protobuf-java"]}"))
|
||||
packedJars(protobufFull())
|
||||
packedJars(project(":core:builtins", configuration = "builtins"))
|
||||
sideJars(projectDist(":kotlin-script-runtime"))
|
||||
sideJars(projectDist(":kotlin-stdlib"))
|
||||
|
||||
@@ -55,6 +55,7 @@ include ":kotlin-build-common",
|
||||
":core:descriptors.runtime",
|
||||
":core:builtins",
|
||||
":core:util.runtime",
|
||||
":custom-dependencies:protobuf-relocated",
|
||||
":custom-dependencies:protobuf-lite",
|
||||
":idea:idea-jvm",
|
||||
":idea:idea-maven",
|
||||
|
||||
@@ -240,8 +240,6 @@
|
||||
<mapper type="flatten"/>
|
||||
</unzip>
|
||||
|
||||
<get-protobuf-and-rename-packages/>
|
||||
|
||||
<download_teamcity_artifact
|
||||
teamcity.server.url="https://teamcity.jetbrains.com"
|
||||
build.locator.request="${markdown.locator}"
|
||||
@@ -253,68 +251,6 @@
|
||||
|
||||
</target>
|
||||
|
||||
<macrodef name="get-protobuf-and-rename-packages">
|
||||
<sequential>
|
||||
<macrodef name="rename-packages-in-binaries">
|
||||
<attribute name="target.jar"/>
|
||||
<attribute name="source.jar"/>
|
||||
|
||||
<sequential>
|
||||
<delete file="@{target.jar}" failonerror="false"/>
|
||||
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="${dependencies}/jarjar.jar"/>
|
||||
<jarjar jarfile="@{target.jar}" filesonly="true">
|
||||
<zipfileset src="@{source.jar}">
|
||||
<exclude name="META-INF/maven/com.google.protobuf/protobuf-java/pom.properties"/>
|
||||
</zipfileset>
|
||||
<rule pattern="com.google.protobuf.**" result="org.jetbrains.kotlin.protobuf.@1"/>
|
||||
</jarjar>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="rename-packages-in-sources">
|
||||
<attribute name="target.jar"/>
|
||||
<attribute name="source.jar"/>
|
||||
|
||||
<sequential>
|
||||
<local name="tmp.src"/>
|
||||
<property name="tmp.src" value="${dependencies}/download/protobuf-src"/>
|
||||
|
||||
<delete dir="${tmp.src}" failonerror="false"/>
|
||||
<unzip src="@{source.jar}" dest="${tmp.src}">
|
||||
<patternset includes="**/*"/>
|
||||
</unzip>
|
||||
|
||||
<replaceregexp match="com\.google\.protobuf" replace="org.jetbrains.kotlin.protobuf" flags="g">
|
||||
<fileset dir="${tmp.src}/" includes="**/*.java"/>
|
||||
</replaceregexp>
|
||||
|
||||
<move file="${tmp.src}/com/google/protobuf"
|
||||
tofile="${tmp.src}/org/jetbrains/kotlin/protobuf"/>
|
||||
|
||||
<delete file="@{target.jar}" failonerror="false"/>
|
||||
<zip destfile="@{target.jar}" basedir="${tmp.src}"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<property name="protobuf.version" value="2.6.1"/>
|
||||
|
||||
<!-- Download protobuf and rename packages -->
|
||||
<get-maven-library prefix="com/google/protobuf" lib="protobuf-java" version="${protobuf.version}"/>
|
||||
<delete file="${dependencies}/protobuf-java-${protobuf.version}.jar"/>
|
||||
<delete file="${dependencies}/protobuf-java-${protobuf.version}-sources.jar"/>
|
||||
|
||||
<rename-packages-in-binaries
|
||||
source.jar="${dependencies}/download/protobuf-java-${protobuf.version}.jar"
|
||||
target.jar="${dependencies}/protobuf-${protobuf.version}.jar"
|
||||
/>
|
||||
|
||||
<rename-packages-in-sources
|
||||
source.jar="${dependencies}/download/protobuf-java-${protobuf.version}-sources.jar"
|
||||
target.jar="${dependencies}/protobuf-${protobuf.version}-sources.jar"
|
||||
/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="download_teamcity_artifact">
|
||||
<attribute name="teamcity.server.url"/>
|
||||
<attribute name="build.locator.request"/>
|
||||
|
||||
Reference in New Issue
Block a user