in buildSrc/src/main/kotlin/org/jetbrains/compose/reload/build/withShadowingPlugin.kt [44:135]
override fun apply(target: Project) {
target.plugins.apply(ShadowPlugin::class.java)
/* Setup configurations */
val implementation = target.configurations.getByName("implementation")
val runtimeOnly = target.configurations.getByName("runtimeOnly")
val compileOnly = target.configurations.getByName("compileOnly")
val shadow = target.configurations.getByName("shadow")
val shadowedImplementation = target.configurations.register("shadowedImplementation")
val shadowRuntimeElements = target.configurations.getByName("shadowRuntimeElements")
val sourcesElements = target.configurations.getByName("sourcesElements")
val javadocElements = target.configurations.getByName("javadocElements")
/**
* Everything that is declared as regular 'implementation' or 'runtimeOnly' dependency
* shall behave as 'regular' runtime dependency (not shadowed)
*/
shadow.extendsFrom(implementation)
shadow.extendsFrom(runtimeOnly)
/**
* Dependencies within the 'shadowImplementation' have to be listed *all* exhaustively
* (no transitivity, to avoid unintended shadowing)
*/
shadowedImplementation.configure {
isCanBeConsumed = false
isCanBeResolved = true
isTransitive = false
}
/**
* Everything, embedded into the 'shadowImplementation' shall be available during compilation
*/
compileOnly.extendsFrom(shadowedImplementation.get())
/**
* Configure the jar:
* Let the 'shadow' jar be the 'default' jar and call the unshaded jar 'light'
*/
val shadowJar = target.tasks.named<ShadowJar>("shadowJar")
val jar = target.tasks.named<Jar>("jar")
shadowJar.configure {
archiveClassifier.set("")
configurations.set(listOf(shadowedImplementation.get()))
}
jar.configure {
archiveClassifier.set("light")
}
/* Configure the publication by creating a new component */
val component = target.serviceOf<SoftwareComponentFactory>().adhoc("shadowed")
component.addVariantsFromConfiguration(shadowRuntimeElements) {
mapToMavenScope("runtime")
}
component.addVariantsFromConfiguration(sourcesElements) {
mapToOptional()
}
component.addVariantsFromConfiguration(javadocElements) {
mapToOptional()
}
/**
* Configure the publishing:
* We do want to publish the 'shadow' component only
*/
target.plugins.withId("maven-publish") {
target.extensions.configure<PublishingExtension>() {
publications.register<MavenPublication>("default") {
from(component)
}
}
}
val checkTask = target.tasks.register("checkShadowedJar", JarConentCheck::class.java) {
inputs.files(shadowJar)
}
target.tasks.named("check").configure {
dependsOn(checkTask)
}
/* create extension */
val extension = target.extensions.add(
WithShadowingExtension::class.java, "withShadowing",
WithShadowingExtension(shadowJar)
)
}