如何使用Gradle的maven-publish插件和Kotlin DSL发布一个带有空POM的shadow JAR?

huangapple go评论84阅读模式
英文:

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

问题

以下是翻译好的内容:

来自https://imperceptiblethoughts.com/shadow/publishing的Groovy示例:

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

我对Kotlin版本的最佳尝试:

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

在上述的Kotlin版本中,被影子化的依赖关系会显示在生成的POM中作为运行时依赖关系,这违背了影子化的目的。

英文:

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 -&gt;
      project.shadow.component(publication)
    }
  }
}

My best attempt at the Kotlin version:

publishing {
  publications {
    create&lt;MavenPublication&gt;(&quot;pluginMaven&quot;) {
      artifact(tasks[&quot;shadowJar&quot;])
      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.

答案1

得分: 1

以下是翻译好的部分:

解决方案是

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


有关更多背景信息,请参阅[此 GitHub 问题](https://github.com/johnrengelman/shadow/issues/598)。

<details>
<summary>英文:</summary>

The solution is 

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


Some background in [this github issue](https://github.com/johnrengelman/shadow/issues/598).

</details>



huangapple
  • 本文由 发表于 2020年9月17日 10:33:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63930436.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定