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")
|
fun DependencyHandler.projectClasses(name: String): ProjectDependency = project(name, configuration = "classes-dirs")
|
||||||
|
|
||||||
val protobufLiteProject = ":custom-dependencies:protobuf-lite"
|
val protobufLiteProject = ":custom-dependencies:protobuf-lite"
|
||||||
|
val protobufRelocatedProject = ":custom-dependencies:protobuf-relocated"
|
||||||
fun DependencyHandler.protobufLite(): ProjectDependency =
|
fun DependencyHandler.protobufLite(): ProjectDependency =
|
||||||
project(protobufLiteProject, configuration = "default").apply { isTransitive = false }
|
project(protobufLiteProject, configuration = "default").apply { isTransitive = false }
|
||||||
val protobufLiteTask = "$protobufLiteProject:prepare"
|
val protobufLiteTask = "$protobufLiteProject:prepare"
|
||||||
|
|
||||||
fun DependencyHandler.protobufFull(): ProjectDependency =
|
fun DependencyHandler.protobufFull(): ProjectDependency =
|
||||||
project(protobufLiteProject, configuration = "relocated").apply { isTransitive = false }
|
project(protobufRelocatedProject, configuration = "default").apply { isTransitive = false }
|
||||||
val protobufFullTask = "$protobufLiteProject:prepare-relocated-protobuf"
|
val protobufFullTask = "$protobufLiteProject:prepare"
|
||||||
|
|
||||||
fun File.matchMaybeVersionedArtifact(baseName: String) = name.matches(baseName.toMaybeVersionedJarRegex())
|
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.BufferedOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.util.jar.JarEntry
|
import java.util.jar.JarEntry
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
import org.gradle.language.assembler.tasks.Assemble
|
|
||||||
|
|
||||||
buildscript {
|
val relocatedProtobuf by configurations.creating
|
||||||
repositories {
|
val relocatedProtobufSources by configurations.creating
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
val resultsCfg = configurations.create("default")
|
||||||
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 protobufVersion = rootProject.extra["versions.protobuf-java"]
|
val protobufVersion = rootProject.extra["versions.protobuf-java"]
|
||||||
val protobufJarPrefix = "protobuf-$protobufVersion"
|
val protobufJarPrefix = "protobuf-$protobufVersion"
|
||||||
val renamedOutputJarPath = "$buildDir/jars/$protobufJarPrefix-relocated.jar"
|
|
||||||
val outputJarPath = "$buildDir/libs/$protobufJarPrefix-lite.jar"
|
val outputJarPath = "$buildDir/libs/$protobufJarPrefix-lite.jar"
|
||||||
|
|
||||||
artifacts.add(mainCfg.name, File(outputJarPath))
|
|
||||||
artifacts.add(relocatedCfg.name, File(renamedOutputJarPath))
|
|
||||||
|
|
||||||
dependencies {
|
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") {
|
task("prepare") {
|
||||||
archiveName = renamedOutputJarPath
|
// TODO: find out why it doesn't work without explicit dependsOn
|
||||||
this.configurations = listOf(relocatedCfg)
|
dependsOn(":custom-dependencies:protobuf-relocated:prepare")
|
||||||
from(mainCfg.files.find { it.name.startsWith("protobuf-java") }?.canonicalPath)
|
val inputJar = relocatedProtobuf.files.single()
|
||||||
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
|
|
||||||
inputs.files(inputJar)
|
inputs.files(inputJar)
|
||||||
outputs.file(outputJarPath)
|
outputs.file(outputJarPath)
|
||||||
doFirst {
|
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)
|
val clean by task<Delete> {
|
||||||
|
delete(buildDir)
|
||||||
tasks.withType<Assemble>() {
|
}
|
||||||
dependsOn(mainCfg)
|
|
||||||
|
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
|
val sideJars by configurations.creating
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
packedJars(preloadedDeps("protobuf-${rootProject.extra["versions.protobuf-java"]}"))
|
packedJars(protobufFull())
|
||||||
packedJars(project(":core:builtins", configuration = "builtins"))
|
packedJars(project(":core:builtins", configuration = "builtins"))
|
||||||
sideJars(projectDist(":kotlin-script-runtime"))
|
sideJars(projectDist(":kotlin-script-runtime"))
|
||||||
sideJars(projectDist(":kotlin-stdlib"))
|
sideJars(projectDist(":kotlin-stdlib"))
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ include ":kotlin-build-common",
|
|||||||
":core:descriptors.runtime",
|
":core:descriptors.runtime",
|
||||||
":core:builtins",
|
":core:builtins",
|
||||||
":core:util.runtime",
|
":core:util.runtime",
|
||||||
|
":custom-dependencies:protobuf-relocated",
|
||||||
":custom-dependencies:protobuf-lite",
|
":custom-dependencies:protobuf-lite",
|
||||||
":idea:idea-jvm",
|
":idea:idea-jvm",
|
||||||
":idea:idea-maven",
|
":idea:idea-maven",
|
||||||
|
|||||||
@@ -240,8 +240,6 @@
|
|||||||
<mapper type="flatten"/>
|
<mapper type="flatten"/>
|
||||||
</unzip>
|
</unzip>
|
||||||
|
|
||||||
<get-protobuf-and-rename-packages/>
|
|
||||||
|
|
||||||
<download_teamcity_artifact
|
<download_teamcity_artifact
|
||||||
teamcity.server.url="https://teamcity.jetbrains.com"
|
teamcity.server.url="https://teamcity.jetbrains.com"
|
||||||
build.locator.request="${markdown.locator}"
|
build.locator.request="${markdown.locator}"
|
||||||
@@ -253,68 +251,6 @@
|
|||||||
|
|
||||||
</target>
|
</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">
|
<macrodef name="download_teamcity_artifact">
|
||||||
<attribute name="teamcity.server.url"/>
|
<attribute name="teamcity.server.url"/>
|
||||||
<attribute name="build.locator.request"/>
|
<attribute name="build.locator.request"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user