bj4947
bj4947

Reputation: 910

Maven-Publish does not publish API/Implementation dependencies in POM

I am using maven-publish plugin in gradle to publish artifacts. I need to generate a POM file that contains dependencies so that my consumers can fetch the needed dependencies.

Since maven-publish does not by default contains dependencies onto POM file, I had to use

pom.withXml {
            def dependenciesNode = asNode().appendNode('dependencies')
            configurations.compile.allDependencies.each {
                def dependencyNode = dependenciesNode.appendNode('dependency')
                dependencyNode.appendNode('groupId', it.group)
                dependencyNode.appendNode('artifactId', it.name)
                dependencyNode.appendNode('version', it.version)
                dependencyNode.appendNode('scope', 'compile')
            }
        }

It was all working fine to me until I swapped keyword compile to api or Implementation. the published POM does not contain any dependencies uses keyword api or Implementation. I had to use compile to make it included in POM file, am I missing anything here?

Upvotes: 4

Views: 1182

Answers (2)

bj4947
bj4947

Reputation: 910

After couple of hours searching online, I just realized that the property you include POM file is changed as well.

It now become

//for implementation dependencies
configurations.implementation.allDependencies.each { ... }

//for api dependencies
configurations.api.allDependencies.each { ... }

However,

configurations.implementation.allDependencies.each { ... }

seems includes api dependencies in the POM file already.

Upvotes: 3

Abid Khan
Abid Khan

Reputation: 199

you can simply skip the scope part, you hardly come across maven dependencies with scopes. ':D

Upvotes: 0

Related Questions