Could not apply withXml() to generated POM : Configuration with name 'compile' not found


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

            // Tell maven to prepare the generated "*.aar" file for publishing

            pom.withXml {
                def dependencies = asNode().appendNode('dependencies')

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

gradle Dependency

classpath ''


* What went wrong:
Execution failed for task ':identitykit:generatePomFileForAarPublication'.
> Could not apply withXml() to generated POM
   > Configuration with name 'compile' not found.

I know compile is deprecated. So, tried ‘implementation’ and ‘api’ as well. Getting same error.

It was deprecated for many many years and since Gradle 7 does not exist anymore unless you create a custom configuration with that name.

With implementation and api you probably get a different error, namely that they are not resolvable. If you get that they don’t exist, you probably not apply the plugins that would create them, but impossible to say from only that snippet.

But actually, the whole snippet is an extremely bad idea anyway. Especially as the Gradle Module Metadata would disagree then on the declared dependencies with the POM which is very bad. Better would be to model the build properly so that the POM looks like expected automatically.