英文:
Generate Maven "provided" dependency in pom.xml from Gradle "compileOnly"
问题
如果我理解正确,Gradle的compileOnly
依赖对应于Gradle的旧版本provided
,同时也对应于Maven POM的provided
。它在Gradle世界中运行得很完美。
但是,compileOnly
在maven-publish
生成的pom.xml
中不会生成任何provided
依赖。
我们正在使用Gradle将Maven构件发布到Maven Central。我们想要从Gradle的compileOnly
中明确声明provided
依赖项在发布的pom.xml
中。
有没有人知道是否有任何简单的方法来做到这一点?或者,我们是否需要在以下位置编写自己的Gradle脚本:
publishing {
publications {
maven(MavenPublication) {
pom {
/* 我们自己的Gradle脚本来声明provided依赖项。 */
}
}
}
}
英文:
If I understand correctly, Gradle's compileOnly
dependency corresponds to Gradle's older provided
, and at the same time, Maven POM's provided
. It works perfectly in the Gradle world.
But, compileOnly
does not generate any provided
dependency in pom.xml
generated by maven-publish
.
We are publishing a Maven artifact to Maven Central, using Gradle. We would like to declare provided
explicitly in the published pom.xml
from Gradle's compileOnly
.
Does anyone know if there is any simple way to do that? Or, do we need to write our own Gradle scripting in :
publishing {
publications {
maven(MavenPublication) {
pom {
/* Our own Gradle scripting to declare provided dependencies. */
}
}
}
}
答案1
得分: 1
Sure, here's the translated part:
publishing {
publications {
maven(MavenPublication) {
pom {
withXml {
project.configurations.compileOnly.allDependencies.each { dependency ->
asNode().dependencies[0].appendNode("dependency").with {
it.appendNode("groupId", dependency.group)
it.appendNode("artifactId", dependency.name)
it.appendNode("version", dependency.version)
it.appendNode("scope", "provided")
}
}
}
}
}
}
}
英文:
I know we can tweak it by scripting dirty like below, but we basically don't want to "script" in build.gradle
as far as possible.
publishing {
publications {
maven(MavenPublication) {
pom {
withXml {
project.configurations.compileOnly.allDependencies.each { dependency ->
asNode().dependencies[0].appendNode("dependency").with {
it.appendNode("groupId", dependency.group)
it.appendNode("artifactId", dependency.name)
it.appendNode("version", dependency.version)
it.appendNode("scope", "provided")
}
}
}
}
}
}
}
答案2
得分: 0
I think scripting is the way to go... you can create a method och pass the pom e.g
发布 {
发布物 {
mavenDependencyList(MavenPublication) {
修复依赖范围(pom)
}
}
}
void 修复依赖范围(pom) {
pom.withXml {
asNode().dependencies.''.findAll() {
it.scope.text() == 'compileOnly' && project.configurations.compile.allDependencies.find { dep ->
dep.name == it.artifactId.text()
}
}.each() {
it.scope.value = 'provided'
}
}
}
英文:
I think scripting is the way to go... you can create a method och pass the pom e.g
publishing {
publications {
mavenDependencyList(MavenPublication) {
fixDependencyScope(pom)
}
}
}
void fixDependencyScope(pom) {
pom.withXml {
asNode().dependencies.'*'.findAll() {
it.scope.text() == 'compileOnly' && project.configurations.compile.allDependencies.find { dep ->
dep.name == it.artifactId.text()
}
}.each() {
it.scope*.value = 'provided'
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论