4

maven-publish在 gradle 中使用插件来发布工件。我需要生成一个包含依赖项的 POM 文件,以便我的消费者可以获取所需的依赖项。

由于maven-publish默认情况下不包含对 POM 文件的依赖项,因此我不得不使用

pom.withXml {
            def dependenciesNode = asNode().appendNode('dependencies')
            configurations.compile.allDependencies.each {
                def dependencyNode = dependenciesNode.appendNode('dependency')
                dependencyNode.appendNode('groupId', it.group)
                dependencyNode.appendNode('artifactId', it.name)
                dependencyNode.appendNode('version', it.version)
                dependencyNode.appendNode('scope', 'compile')
            }
        }

compile在我将关键字换成apior之前,这一切对我来说都很好Implementation。发布的 POM 不包含任何依赖项,使用关键字apiImplementation. 我不得不使用compile它来使它包含在 POM 文件中,我在这里遗漏了什么吗?

4

2 回答 2

3

在网上搜索了几个小时后,我才意识到您包含的 POM 文件的属性也发生了变化。

现在变成

//for implementation dependencies
configurations.implementation.allDependencies.each { ... }

//for api dependencies
configurations.api.allDependencies.each { ... }

然而,

configurations.implementation.allDependencies.each { ... }

似乎api已经在 POM 文件中包含依赖项。

于 2018-04-05T05:26:51.917 回答
0

您可以简单地跳过范围部分,您几乎不会遇到与范围有关的 Maven 依赖项。':D

于 2018-04-05T04:47:05.557 回答