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") {