问题描述
我正在GitHub上的一个自我维护的maven仓库发布一个工件A.该项目具有几个传递依赖关系B,C,D,托管在不同的存储库中。依赖项B,C,D在生成p的pom.xml(uploadArchives)的渐变中指定,但不指定到存储库的路径。因此,当将A指定为另一个项目中的依赖关系时,传递依赖关系B,C,D不被下载。是否可以告诉毕业者将A的pom.xml中的B,C,D的maven存储库。
这样做的方法是定制生成的POM。这是一个例子,假设 maven
插件用于发布:
uploadArchives {
repositories {
mavenDeployer {
//将更多信息添加到生成的POM
//语法映射1:1到POM语法
pom.project {
//还可以以编程方式生成
//,基于build
资源库中声明的repos {
repository {
id'myrepo'
url'http // my.repo.com'
}
}
}
}
}
}
新的孵化 maven-publish
插件提供了一个类似的钩子。
请注意,Gradle本身不符合在解析依赖关系时在POM中声明的存储库,而只是声明为b的存储库你的建设。另请查看。
I am publishing an artifact A to a self maintained maven repository on GitHub. The project has several transitive dependencies B, C, D which are hosted in different repositories. The dependencies B, C, D are specified in the gradle generated pom.xml (uploadArchives) of A but not the paths to the repositories. Therefore, the transitive dependencies B, C, D are not downloaded when A is specified as a dependency in another project.
Is it possible to tell gradle to include the urls of the maven repositories of B, C, D in the pom.xml of A?
The way to do this is to customize the generated POM. Here is an example, assuming that the maven
plugin is used for publishing:
uploadArchives {
repositories {
mavenDeployer {
// add further information to the generated POM
// syntax maps 1:1 to POM syntax
pom.project {
// could also generate this programmatically
// based on the repos declared in the build
repositories {
repository {
id 'myrepo'
url 'http//my.repo.com'
}
}
}
}
}
}
The new, incubating maven-publish
plugin offers a similar hook.
Note that Gradle itself doesn't honor repositories declared in POMs when resolving dependencies, but only repositories declared by your build. Also check out http://www.sonatype.com/people/2009/02/why-putting-repositories-in-your-poms-is-a-bad-idea/.
这篇关于如何在Gradle生成的POM中声明存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!