Make a project-wide embeddedComponents configuration for embedding external binaries to project artifacts

This commit is contained in:
Yan Zhulanow
2018-02-22 21:45:00 +03:00
parent 3c06dd7464
commit 6e65a4810e
9 changed files with 116 additions and 37 deletions
+18
View File
@@ -5,6 +5,8 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.tasks.AbstractCopyTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.project
import java.io.File
@@ -98,3 +100,19 @@ fun firstFromJavaHomeThatExists(vararg paths: String): File? =
fun toolsJar(): File? = firstFromJavaHomeThatExists("../lib/tools.jar", "../Classes/tools.jar")
object EmbeddedComponents {
val CONFIGURATION_NAME = "embeddedComponents"
}
fun Project.containsEmbeddedComponents() {
configurations.create(EmbeddedComponents.CONFIGURATION_NAME)
}
fun AbstractCopyTask.fromEmbeddedComponents() {
val embeddedComponents = project.configurations.getByName(EmbeddedComponents.CONFIGURATION_NAME)
if (this is ShadowJar) {
from(embeddedComponents)
} else {
embeddedComponents.forEach { from(if (it.isDirectory) it else project.zipTree(it)) }
}
}
@@ -107,7 +107,10 @@ fun generateKotlinPluginArtifactFile(rootProject: Project): PFile {
val root = Root()
// Copy kotlinc directory
root.add(DirectoryCopy(File(rootProject.extra["distKotlinHomeDir"].toString())))
root.add(Directory("kotlinc").apply {
val kotlincDirectory = rootProject.extra["distKotlinHomeDir"].toString()
add(DirectoryCopy(File(kotlincDirectory)))
})
for (task in ideaPluginTasks) {
val spec = task.rootSpec.children.filterIsInstance<SingleParentCopySpec>().singleOrNull()
@@ -146,11 +149,11 @@ fun generateKotlinPluginArtifactFile(rootProject: Project): PFile {
root.getDirectory(targetDir).add(this)
}
val fatJarContentsConfiguration = sourcePath.project.configurations
.findByName("fatJarContents")?.resolvedConfiguration
val embeddedComponents = sourcePath.project.configurations
.findByName(EmbeddedComponents.CONFIGURATION_NAME)?.resolvedConfiguration
if (fatJarContentsConfiguration != null) {
for ((_, _, dependency) in listOf(fatJarContentsConfiguration to Scope.COMPILE).collectDependencies()) {
if (embeddedComponents != null) {
for ((_, _, dependency) in listOf(embeddedComponents to Scope.COMPILE).collectDependencies()) {
if (dependency.configuration == "runtimeElements") {
archiveForJar.add(ModuleOutput(dependency.moduleName + ".src"))
} else if (dependency.configuration == "tests-jar" || dependency.configuration == "jpsTest") {
@@ -9,8 +9,7 @@ jvmTarget = "1.6"
val nativePlatformVariants: List<String> by rootProject.extra
// Do not rename, used in JPS importer
val fatJarContents by configurations.creating
containsEmbeddedComponents()
dependencies {
compileOnly(project(":compiler:util"))
@@ -18,10 +17,11 @@ dependencies {
compileOnly(project(":compiler:daemon-common"))
compileOnly(project(":kotlin-reflect-api"))
compileOnly(commonDep("net.rubygrapefruit", "native-platform"))
fatJarContents(project(":compiler:daemon-common")) { isTransitive = false }
fatJarContents(commonDep("net.rubygrapefruit", "native-platform"))
embeddedComponents(project(":compiler:daemon-common")) { isTransitive = false }
embeddedComponents(commonDep("net.rubygrapefruit", "native-platform"))
nativePlatformVariants.forEach {
fatJarContents(commonDep("net.rubygrapefruit", "native-platform", "-$it"))
embeddedComponents(commonDep("net.rubygrapefruit", "native-platform", "-$it"))
}
}
@@ -32,8 +32,9 @@ sourceSets {
runtimeJar(task<ShadowJar>("shadowJar")) {
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(fatJarContents)
fromEmbeddedComponents()
}
sourcesJar()
javadocJar()
+61 -8
View File
@@ -58,6 +58,7 @@
"configurations": [
"archives",
"default",
"embeddedComponents",
"runtimeJar"
],
"extensions": {
@@ -199,8 +200,7 @@
"testImplementation",
"testRuntime",
"testRuntimeClasspath",
"testRuntimeOnly",
"tests-jar"
"testRuntimeOnly"
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
@@ -545,6 +545,7 @@
"compileOnly",
"default",
"distJar",
"embeddedComponents",
"implementation",
"jpsTest",
"kapt",
@@ -1009,7 +1010,7 @@
"compileOnly",
"default",
"distJar",
"fatJarContents",
"embeddedComponents",
"implementation",
"jpsTest",
"kapt",
@@ -1242,7 +1243,7 @@
"configurations": [
"archives",
"default",
"fatJarContents",
"embeddedComponents",
"runtimeJar"
],
"extensions": {
@@ -1751,10 +1752,18 @@
"compileOnly",
"default",
"distJar",
"experimentalCompile",
"experimentalCompileClasspath",
"experimentalCompileOnly",
"experimentalImplementation",
"experimentalRuntime",
"experimentalRuntimeClasspath",
"experimentalRuntimeOnly",
"implementation",
"kapt",
"kaptAnnotations",
"kaptBuiltins",
"kaptExperimental",
"kaptTest",
"mainJar",
"runtime",
@@ -1992,6 +2001,13 @@
"compileOnly",
"default",
"distJar",
"experimentalCompile",
"experimentalCompileClasspath",
"experimentalCompileOnly",
"experimentalImplementation",
"experimentalRuntime",
"experimentalRuntimeClasspath",
"experimentalRuntimeOnly",
"implementation",
"merger",
"nodeDist",
@@ -2970,7 +2986,8 @@
"testImplementation",
"testRuntime",
"testRuntimeClasspath",
"testRuntimeOnly"
"testRuntimeOnly",
"tests-jar"
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
@@ -3006,7 +3023,8 @@
"testImplementation",
"testRuntime",
"testRuntimeClasspath",
"testRuntimeOnly"
"testRuntimeOnly",
"tests-jar"
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
@@ -3863,7 +3881,8 @@
"testImplementation",
"testRuntime",
"testRuntimeClasspath",
"testRuntimeOnly"
"testRuntimeOnly",
"tests-jar"
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
@@ -3910,6 +3929,38 @@
"reporting": "org.gradle.api.reporting.ReportingExtension"
}
},
":jps-plugin:jps-services-declarations": {
"conventions": {
"base": "org.gradle.api.plugins.BasePluginConvention",
"java": "org.gradle.api.plugins.JavaPluginConvention"
},
"configurations": [
"apiElements",
"archives",
"compile",
"compileClasspath",
"compileOnly",
"default",
"implementation",
"jpsTest",
"runtime",
"runtimeClasspath",
"runtimeElements",
"runtimeOnly",
"testCompile",
"testCompileClasspath",
"testCompileOnly",
"testImplementation",
"testRuntime",
"testRuntimeClasspath",
"testRuntimeOnly"
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
"defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet",
"reporting": "org.gradle.api.reporting.ReportingExtension"
}
},
":js:js.ast": {
"conventions": {
"base": "org.gradle.api.plugins.BasePluginConvention",
@@ -4586,6 +4637,7 @@
"compileOnly",
"default",
"distJar",
"embeddedComponents",
"implementation",
"jpsTest",
"kapt",
@@ -4940,7 +4992,8 @@
"testImplementation",
"testRuntime",
"testRuntimeClasspath",
"testRuntimeOnly"
"testRuntimeOnly",
"versions"
],
"extensions": {
"ext": "org.gradle.api.plugins.ExtraPropertiesExtension",
@@ -6,8 +6,7 @@ apply { plugin("jps-compatible") }
val robolectricClasspath by configurations.creating
// Do not rename, used in JPS importer
val fatJarContents by configurations.creating
containsEmbeddedComponents()
dependencies {
testCompile(intellijCoreDep()) { includeJars("intellij-core") }
@@ -34,7 +33,7 @@ dependencies {
robolectricClasspath(commonDep("org.robolectric", "robolectric"))
fatJarContents(project(":kotlin-android-extensions-runtime"))
embeddedComponents(project(":kotlin-android-extensions-runtime")) { isTransitive = false }
}
sourceSets {
@@ -43,7 +42,7 @@ sourceSets {
}
runtimeJar {
from(getSourceSetsFrom(":kotlin-android-extensions-runtime")["main"].output.classesDirs)
fromEmbeddedComponents()
}
dist()
@@ -4,6 +4,8 @@ description = "Annotation Processor for Kotlin"
apply { plugin("kotlin") }
apply { plugin("jps-compatible") }
containsEmbeddedComponents()
dependencies {
testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") }
testRuntime(intellijDep())
@@ -23,6 +25,8 @@ dependencies {
testCompile(projectTests(":compiler:tests-common"))
testCompile(commonDep("junit:junit"))
testCompile(project(":kotlin-annotation-processing-runtime"))
embeddedComponents(project(":kotlin-annotation-processing-runtime")) { isTransitive = false }
}
sourceSets {
@@ -30,10 +34,6 @@ sourceSets {
"test" { projectDefault() }
}
runtimeJar {
from(getSourceSetsFrom(":kotlin-annotation-processing-runtime")["main"].output.classesDirs)
}
testsJar {}
projectTest {
@@ -41,7 +41,10 @@ projectTest {
dependsOn(":dist")
}
runtimeJar()
runtimeJar {
fromEmbeddedComponents()
}
sourcesJar()
javadocJar()
+7 -4
View File
@@ -13,16 +13,19 @@ sourceSets {
"test" {}
}
// Do not rename, used in JPS importer
val fatJarContents by configurations.creating
containsEmbeddedComponents()
dependencies {
projectsToShadow.forEach {p ->
fatJarContents(project(p)) { isTransitive = false }
projectsToShadow.forEach { p ->
embeddedComponents(project(p)) { isTransitive = false }
}
}
runtimeJar {
/*
TODO: `fromEmbeddedComponents()` should be used here.
Couldn't use it because of the "must be locked before it can be used to compute a classpath" error.
*/
projectsToShadow.forEach {
dependsOn("$it:classes")
project(it).let { p ->
-1
View File
@@ -23,7 +23,6 @@ val shrink =
val compilerManifestClassPath =
"kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar"
// Do not rename, used in JPS importer
val fatJarContents by configurations.creating
val fatJarContentsStripMetadata by configurations.creating
+4 -4
View File
@@ -21,20 +21,20 @@ val projectsToShadow = listOf(
":core:util.runtime",
":plugins:android-extensions-jps")
// Do not rename, used in JPS importer
val fatJarContents by configurations.creating
containsEmbeddedComponents()
dependencies {
projectsToShadow.forEach {
fatJarContents(project(it)) { isTransitive = false }
embeddedComponents(project(it)) { isTransitive = false }
}
}
runtimeJar<ShadowJar>(task<ShadowJar>("jar")) {
manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.runner.Main")
manifest.attributes.put("Class-Path", "kotlin-stdlib.jar")
from(fatJarContents)
from(files("$rootDir/resources/kotlinManifest.properties"))
fromEmbeddedComponents()
}
ideaPlugin("lib/jps")