Home » Android » android – configurations getByName not working in gradle when publishing POM file to Artifactory

android – configurations getByName not working in gradle when publishing POM file to Artifactory

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’m using a publishing section in my build.gradle file for publishing an Android library to Artifactory:

publishing {
  publications {
    aar(MavenPublication) {
        groupId packageName
        version = libraryVersion
        artifactId project.getName()

        // Tell maven to prepare the generated "*.aar" file for publishing
        artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")

        pom.withXml {
                def dependencies = asNode().appendNode('dependencies')
                configurations.getByName("_releaseCompile").getResolvedConfiguration().getFirstLevelModuleDependencies().each {
                    def dependency = dependencies.appendNode('dependency')
                    dependency.appendNode('groupId', it.moduleGroup)
                    dependency.appendNode('artifactId', it.moduleName)
                    dependency.appendNode('version', it.moduleVersion)
                }
            }
        }
    }
}

It fails with the following error:

Execution failed for task ':smartcardsdk:generatePomFileForAarPublication'.
> Could not apply withXml() to generated POM
> Configuration with name '_releaseCompile' not found.

This was not a problem with Android v2.x. Problem started when I upgraded to Android Studio v3 (and I guess Gradle v3.0.0 as well).

I’m guessing that the configurations are no longer stored with the _releaseCompile name.

Does anyone know what the new “name” should be?

Thanks.

How to&Answers:

Just figured it out. You have to change it to:

"releaseCompileClasspath"