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)

相关文章

安装环境都很简单,就是下载工具需要在华为开发者联盟里注册...
上传的方式有两种,第一种是通过bintray官方出的插件bintray...
转载自: 完美解决Error:SSLpeershutdownincorrectly打开gr...
https://www.jianshu.com/p/9220227cdfb3buildscript{ext.ko...
Markdown版本笔记我的GitHub首页我的博客我的微信我的邮箱My...
 跟着教程做的,已经有了JDK,直接进行后面的步骤,下载安装...