How to declare repositories in Gradle generated POMs

吃可爱长大的小学妹 提交于 2020-01-02 09:59:58

问题


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?


回答1:


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/.



来源:https://stackoverflow.com/questions/17032231/how-to-declare-repositories-in-gradle-generated-poms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!