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

Code:

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

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

            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 'com.android.tools.build:gradle:7.3.1'
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip

Exception:

* 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.