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

3

6

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 ->
Chitin answered 7/10, 2015 at 17:27 Comment(1)
Replace compile with implementation or apiConservation
C
9

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)
Chitin answered 7/10, 2015 at 18:1 Comment(2)
what did you mean by the dp?Edris
what is 'it', it.name,it.versionIzmir
A
2

Compile is deprecated we have to use implementation.

for Example

 configurations.implementation.allDependencies.each {
                if(it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null)
                {
                    def dependencyNode = dependenciesNode.appendNode('dependency')
                    dependencyNode.appendNode('groupId', it.group)
                    dependencyNode.appendNode('artifactId', it.name)
                    dependencyNode.appendNode('version', it.version)
                }
            }
Avrilavrit answered 30/10, 2021 at 19:55 Comment(0)
M
1

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
    }
}
Marchese answered 10/12, 2015 at 23:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.