[英]Exclude dependency from pom using Maven Publish Plugin?
我使用以下插件:
id 'maven-publish'
id "com.github.johnrengelman.shadow" version "7.0.0"
我的依賴:
dependencies {
shadow gradleApi()
shadow localGroovy()
implementation 'com.example:lib:0.1.0'
我的發布塊:
publishing {
publications {
pluginJar(MavenPublication) { publication ->
from project.shadow.component(publication)
artifact sourceJar
}
}
}
當我運行publishToMavenLocal
任務時,我可以看到結果pom.xml
包含我不想要的依賴項。
讓我們說它是:
<dependency>
<groupId>com.example</groupId>
<artifactId>lib</artifactId>
<version>0.1.0</version>
<scope>runtime</scope>
</dependency>
我如何配置publications
塊以從pom.xml
(和模塊)文件中擺脫這種依賴關系?
pom.xml
的依賴項來自apiElements
( compile
范圍)和runtimeElements
( runtime
范圍)配置。 您可以從此配置中刪除要從pom.xml
排除的依賴項。
示例(我將使用 Kotlin DSL,因為我不熟悉 Groovy):
setOf("apiElements", "runtimeElements")
.flatMap { configName -> configurations[configName].hierarchy }
.forEach { configuration ->
configuration.dependencies.removeIf { dependency ->
dependency.name == "lib"
}
}
from(components["java"])
將此代碼轉換為 Groovy 並將其粘貼到您的publication
閉包中。
我發現由於我的庫有一個runtime
依賴項,我可以使用以下內容:
components.java.withVariantsFromConfiguration(configurations.runtimeElements) {
skip()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.