Gradle plugin will publish shadowed jar.
^KT-49227 In Progress
This commit is contained in:
@@ -124,4 +124,41 @@ fun Project.configureKotlinCompileTasksGradleCompatibility() {
|
||||
"-Xuse-ir" // Needed as long as languageVersion is less than 1.5.
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Will allow combining outputs of multiple SourceSets
|
||||
fun Project.publishShadowedJar(
|
||||
sourceSet: SourceSet
|
||||
) {
|
||||
val jarTask = tasks.named<Jar>(sourceSet.jarTaskName)
|
||||
|
||||
val shadowJarTask = embeddableCompilerDummyForDependenciesRewriting(
|
||||
taskName = "$EMBEDDABLE_COMPILER_TASK_NAME${sourceSet.jarTaskName.capitalize()}"
|
||||
) {
|
||||
setupPublicJar(
|
||||
jarTask.flatMap { it.archiveBaseName },
|
||||
jarTask.flatMap { it.archiveClassifier }
|
||||
)
|
||||
addEmbeddedRuntime()
|
||||
from(sourceSet.output)
|
||||
|
||||
// When Gradle traverses the inputs, reject the shaded compiler JAR,
|
||||
// which leads to the content of that JAR being excluded as well:
|
||||
val compilerDummyJarFile = project.provider { project.configurations.getByName("compilerDummyJar").singleFile }
|
||||
exclude { it.file == compilerDummyJarFile.get() }
|
||||
}
|
||||
|
||||
// Removing artifact produced by Jar task
|
||||
configurations[sourceSet.runtimeElementsConfigurationName]
|
||||
.artifacts.removeAll { true }
|
||||
configurations[sourceSet.apiElementsConfigurationName]
|
||||
.artifacts.removeAll { true }
|
||||
|
||||
// Adding instead artifact from shadow jar task
|
||||
configurations {
|
||||
artifacts {
|
||||
add(sourceSet.runtimeElementsConfigurationName, shadowJarTask)
|
||||
add(sourceSet.apiElementsConfigurationName, shadowJarTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
@file:Suppress("unused") // usages in build scripts are not tracked properly
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import com.gradle.publish.PublishTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.artifacts.ConfigurablePublishArtifact
|
||||
@@ -17,6 +16,7 @@ import org.gradle.api.plugins.BasePluginExtension
|
||||
import org.gradle.api.plugins.JavaPlugin
|
||||
import org.gradle.api.plugins.JavaPlugin.*
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.publish.PublishingExtension
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.publish.tasks.GenerateModuleMetadata
|
||||
@@ -314,18 +314,28 @@ fun Project.publishTestJar(projects: List<String>, excludedPaths: List<String>)
|
||||
|
||||
fun ConfigurationContainer.getOrCreate(name: String): Configuration = findByName(name) ?: create(name)
|
||||
|
||||
fun Jar.setupPublicJar(baseName: String, classifier: String = "") {
|
||||
fun Jar.setupPublicJar(
|
||||
baseName: String,
|
||||
classifier: String = ""
|
||||
) = setupPublicJar(
|
||||
project.provider { baseName },
|
||||
project.provider { classifier }
|
||||
)
|
||||
|
||||
fun Jar.setupPublicJar(
|
||||
baseName: Provider<String>,
|
||||
classifier: Provider<String> = project.provider { "" }
|
||||
) {
|
||||
val buildNumber = project.rootProject.extra["buildNumber"] as String
|
||||
this.archiveBaseName.set(baseName)
|
||||
this.archiveClassifier.set(classifier)
|
||||
manifest.attributes.apply {
|
||||
put("Implementation-Vendor", "JetBrains")
|
||||
put("Implementation-Title", baseName)
|
||||
put("Implementation-Title", baseName.get())
|
||||
put("Implementation-Version", buildNumber)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Project.addArtifact(configuration: Configuration, task: Task, artifactRef: Any, body: ConfigurablePublishArtifact.() -> Unit = {}) {
|
||||
artifacts.add(configuration.name, artifactRef) {
|
||||
builtBy(task)
|
||||
|
||||
@@ -131,8 +131,10 @@ fun Project.compilerDummyJar(task: TaskProvider<out Jar>, body: Jar.() -> Unit =
|
||||
}
|
||||
}
|
||||
|
||||
const val EMBEDDABLE_COMPILER_TASK_NAME = "embeddable"
|
||||
fun Project.embeddableCompilerDummyForDependenciesRewriting(
|
||||
taskName: String = "embeddable", body: Jar.() -> Unit = {}
|
||||
taskName: String = EMBEDDABLE_COMPILER_TASK_NAME,
|
||||
body: ShadowJar.() -> Unit = {}
|
||||
): TaskProvider<ShadowJar> {
|
||||
val compilerDummyJar = configurations.getOrCreate("compilerDummyJar")
|
||||
dependencies.add(
|
||||
|
||||
@@ -24,6 +24,7 @@ configure<PluginBundleExtension> {
|
||||
}
|
||||
|
||||
configureGradlePluginCommonSettings()
|
||||
publishShadowedJar(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME])
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
|
||||
@@ -27,6 +27,7 @@ val kotlinGradlePluginAndItsRequired = arrayOf(
|
||||
":kotlin-allopen",
|
||||
":kotlin-noarg",
|
||||
":kotlin-sam-with-receiver",
|
||||
":kotlin-lombok",
|
||||
":kotlin-android-extensions",
|
||||
":kotlin-android-extensions-runtime",
|
||||
":kotlin-parcelize-compiler",
|
||||
|
||||
Reference in New Issue
Block a user