javagradle-plugingradle-kotlin-dslshadowjar

How to publish a shadow jar with an empty pom using gradle maven-publish plugin and Kotlin DSL?


The shadow plugin documentation has an example for groovy but I do not understand how to translate this to Kotlin.

Groovy example from https://imperceptiblethoughts.com/shadow/publishing :

publishing {
  publications {
    shadow(MavenPublication) { publication ->
      project.shadow.component(publication)
    }
  }
}

My best attempt at the Kotlin version:

publishing {
  publications {
    create<MavenPublication>("pluginMaven") {
      artifact(tasks["shadowJar"])
      project.shadow.component(this)
    }
  }
}

With the above Kotlin version, shadowed dependencies show up in the resulting pom as runtime dependencies, which defies of purpose of shadowing.


Solution

  • The solution is

    tasks {
        shadowJar {
           archiveClassifier.set("")
            minimize()
        }
    }
    

    Some background in this github issue.