Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven-publish cannot not apply withXML on pom file (No signature of method)

Ok, so I am having the exact issue as described here:

Android library dependencies missing from POM with Gradle

I copied the provided answer to my gradle file as follows:

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')
                }
            }
        }
    }
}

However I am getting an error when attempting to publishToMavenLocal, and I'm not sure why?

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)

Note: Line 136 is this line:

configurations.compile.allDependencies.each { ModuleDependency dp ->
like image 534
DAC Avatar asked Oct 07 '15 17:10

DAC


2 Answers

So as Karma has it, I found the answer shortly after posting

I just removed the ModuleDependency dp and referred to everything from it, and it got past this error, I see the new nodes in the pom file now.

configurations.compile.allDependencies.each {
    def dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', it.group)
    dependencyNode.appendNode('artifactId', it.name)
    dependencyNode.appendNode('version', it.version)
like image 181
DAC Avatar answered Oct 27 '22 09:10

DAC


The root cause of the crash is that not all dependencies are ModuleDependency objects. Something like the following should fix the problem and lets you still add exclusions (which aren't on the base class).

configurations.compile.allDependencies.each { dp ->
    if (dp instanceof ModuleDependency) {
        // do stuff
    }
}
like image 32
mpkuth Avatar answered Oct 27 '22 10:10

mpkuth