微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Maven-publish不能在pom文件上应用withXML(没有方法签名)

好的,所以我遇到了如下所述的确切问题:

Android library dependencies missing from POM with Gradle

我将提供的答案复制到我的gradle文件中,如下所示:

publishing {
    publications {
        mavenAar(MavenPublication) {
            groupId group
            artifactId 'exampleId'
            version version
            artifact source: file('build/outputs/aar/example-release.aar')

            //The publication doesn't kNow about our dependencies, so we have to manually add them to the pom
            pom.withXml {
                // for dependencies and exclusions
                def dependenciesNode = asNode().appendNode('dependencies')
                configurations.compile.allDependencies.each { ModuleDependency dp ->
                    def dependencyNode = dependenciesNode.appendNode('dependency')
                    dependencyNode.appendNode('groupId', dp.group)
                    dependencyNode.appendNode('artifactId', dp.name)
                    dependencyNode.appendNode('version', dp.version)

                    // for exclusions
                    if (dp.excludeRules.size() > 0) {
                        def exclusions = dependencyNode.appendNode('exclusions')
                        dp.excludeRules.each { ExcludeRule ex ->
                            def exclusion = exclusions.appendNode('exclusion')
                            exclusion.appendNode('groupId', ex.group)
                            exclusion.appendNode('artifactId', ex.module)
                        }
                    }
                }
            }
        }
    }
    repositories {
        mavenLocal()
        maven {
            url  selectDeploymentURL()
            if ( project.hasProperty( 'nexusUser' ) ) {
                credentials {
                    username project.getProperty('nexusUser')
                    password project.getProperty('password')
                }
            }
        }
    }
}

但是在尝试发布ToMavenLocal时遇到错误,我不知道为什么?

FAILURE: Build Failed with an exception.

* Where:
Build file 'path/build.gradle' line: 136

* What went wrong:
Execution Failed for task ':example:generatePomFileForMavenAarPublication'.
        > Could not apply withXml() to generated POM
> No signature of method: build_42xq5bsii69isvukzktk1oy51$_run_closure5_closure19_closure21_closure23_closure24.doCall() is applicable for argument types: (org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency_Decorated) values: [org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency_Decorated@433edba9]
Possible solutions: doCall(org.gradle.api.artifacts.ModuleDependency), findAll(), findAll(), isCase(java.lang.Object), isCase(java.lang.Object)

注意:第136行是这一行:

configurations.compile.allDependencies.each { ModuleDependency dp ->

解决方法:

因为Karma拥有它,我在发布后不久就找到了答案

我刚刚删除了ModuleDependency dp并从中引用了所有内容,并且它已经过了这个错误,我现在看到了pom文件中的新节点.

configurations.compile.allDependencies.each {
    def dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', it.group)
    dependencyNode.appendNode('artifactId', it.name)
    dependencyNode.appendNode('version', it.version)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐