From 4a47fb3ffbf9d30b21f31be425be6562498e0d72 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 9 Nov 2017 14:31:32 +0100 Subject: [PATCH] Switch protobuf usages to regular dependency --- buildSrc/src/main/kotlin/dependencies.kt | 5 +- .../protobuf-lite/build.gradle.kts | 58 ++++++---------- .../protobuf-relocated/build.gradle.kts | 66 +++++++++++++++++++ prepare/idea-plugin/build.gradle.kts | 2 +- settings.gradle | 1 + update_dependencies.xml | 64 ------------------ 6 files changed, 92 insertions(+), 104 deletions(-) create mode 100644 custom-dependencies/protobuf-relocated/build.gradle.kts diff --git a/buildSrc/src/main/kotlin/dependencies.kt b/buildSrc/src/main/kotlin/dependencies.kt index 40a79386ce6..6c26bf64dcc 100644 --- a/buildSrc/src/main/kotlin/dependencies.kt +++ b/buildSrc/src/main/kotlin/dependencies.kt @@ -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()) diff --git a/custom-dependencies/protobuf-lite/build.gradle.kts b/custom-dependencies/protobuf-lite/build.gradle.kts index 959daafea3b..d5d779d1cff 100644 --- a/custom-dependencies/protobuf-lite/build.gradle.kts +++ b/custom-dependencies/protobuf-lite/build.gradle.kts @@ -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("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() { - dependsOn(mainCfg) +val clean by task { + delete(buildDir) +} + +artifacts.add("archives", relocatedProtobufSources.files.single()) { + classifier = "sources" } diff --git a/custom-dependencies/protobuf-relocated/build.gradle.kts b/custom-dependencies/protobuf-relocated/build.gradle.kts new file mode 100644 index 00000000000..14d4a381152 --- /dev/null +++ b/custom-dependencies/protobuf-relocated/build.gradle.kts @@ -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 { + 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 { + 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 { + 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(buildDir) +} \ No newline at end of file diff --git a/prepare/idea-plugin/build.gradle.kts b/prepare/idea-plugin/build.gradle.kts index 6881d6887a2..9a1fb664941 100644 --- a/prepare/idea-plugin/build.gradle.kts +++ b/prepare/idea-plugin/build.gradle.kts @@ -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")) diff --git a/settings.gradle b/settings.gradle index 780e978f2ab..6c5a4318ca7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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", diff --git a/update_dependencies.xml b/update_dependencies.xml index 94b5ad42dba..2175925feee 100644 --- a/update_dependencies.xml +++ b/update_dependencies.xml @@ -240,8 +240,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -