Fix shadow packaging in code gen artifact (#1214)

* Update to shadow 6.0

* Exclude kotlinpoet core artifact from shading

* Replace runtime scopes with compile

* Opportunistically fix old artifact() dep

Gradle 6.6 supports providers now

* Use api instead

* Add link

* Remove accidental gradle plugin config

This only applies to gradle plugins
This commit is contained in:
Zac Sweers
2020-09-18 21:43:11 -04:00
committed by GitHub
parent 9ee711adce
commit 517ea36fe5

View File

@@ -22,7 +22,7 @@ plugins {
kotlin("jvm") kotlin("jvm")
kotlin("kapt") kotlin("kapt")
id("com.vanniktech.maven.publish") id("com.vanniktech.maven.publish")
id("com.github.johnrengelman.shadow") version "5.2.0" id("com.github.johnrengelman.shadow") version "6.0.0"
} }
tasks.withType<KotlinCompile>().configureEach { tasks.withType<KotlinCompile>().configureEach {
@@ -38,26 +38,31 @@ tasks.withType<KotlinCompile>().configureEach {
val shade: Configuration = configurations.maybeCreate("compileShaded") val shade: Configuration = configurations.maybeCreate("compileShaded")
configurations.getByName("compileOnly").extendsFrom(shade) configurations.getByName("compileOnly").extendsFrom(shade)
dependencies { dependencies {
implementation(project(":moshi")) // Use `api` because kapt will not resolve `runtime` dependencies without it, only `compile`
implementation(kotlin("reflect")) // https://youtrack.jetbrains.com/issue/KT-41702
api(project(":moshi"))
api(kotlin("reflect"))
shade(Dependencies.Kotlin.metadata) { shade(Dependencies.Kotlin.metadata) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
} }
implementation(Dependencies.KotlinPoet.kotlinPoet) api(Dependencies.KotlinPoet.kotlinPoet)
shade(Dependencies.KotlinPoet.metadata) { shade(Dependencies.KotlinPoet.metadata) {
exclude(group = "org.jetbrains.kotlin") exclude(group = "org.jetbrains.kotlin")
exclude(group = "com.squareup", module = "kotlinpoet")
} }
shade(Dependencies.KotlinPoet.metadataSpecs) { shade(Dependencies.KotlinPoet.metadataSpecs) {
exclude(group = "org.jetbrains.kotlin") exclude(group = "org.jetbrains.kotlin")
exclude(group = "com.squareup", module = "kotlinpoet")
} }
shade(Dependencies.KotlinPoet.elementsClassInspector) { shade(Dependencies.KotlinPoet.elementsClassInspector) {
exclude(group = "org.jetbrains.kotlin") exclude(group = "org.jetbrains.kotlin")
exclude(group = "com.squareup", module = "kotlinpoet")
} }
implementation(Dependencies.asm) api(Dependencies.asm)
implementation(Dependencies.AutoService.annotations) api(Dependencies.AutoService.annotations)
kapt(Dependencies.AutoService.processor) kapt(Dependencies.AutoService.processor)
implementation(Dependencies.Incap.annotations) api(Dependencies.Incap.annotations)
kapt(Dependencies.Incap.processor) kapt(Dependencies.Incap.processor)
// Copy these again as they're not automatically included since they're shaded // Copy these again as they're not automatically included since they're shaded
@@ -94,18 +99,3 @@ artifacts {
runtime(shadowJar) runtime(shadowJar)
archives(shadowJar) archives(shadowJar)
} }
// Shadow plugin doesn't natively support gradle metadata, so we have to tell the maven plugin where
// to get a jar now.
afterEvaluate {
configure<PublishingExtension> {
publications.withType<MavenPublication>().configureEach {
if (name == "pluginMaven") {
// This is to properly wire the shadow jar's gradle metadata and pom information
setArtifacts(artifacts.matching { it.classifier != "" })
// Ugly but artifact() doesn't support TaskProviders
artifact(shadowJar.get())
}
}
}
}