Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Map gradle 'compileOnly' to 'provided' in generated pom (generatePom...)

Tags:

maven

gradle

I am using gradle 4.3.1 I have dependencies in scope compileOnly when I publish to maven I see that these dependencies are not in the pom file.

I would like to map them to provided scope of maven.

How can I do that?

like image 890
igreenfield Avatar asked Oct 17 '25 08:10

igreenfield


1 Answers

I'm not aware of any clean solution (maven-publish plugin is still incubating), so I took inspiration from https://stackoverflow.com/a/25201395/2838501 and have a dirty solution:

publications {
    mavenJava(MavenPublication) {
        from components.java

        pom.withXml {
            project.configurations.compileOnly.allDependencies.each { dep ->
                asNode().dependencies[0].appendNode('dependency').with {
                    it.appendNode('groupId', dep.group)
                    it.appendNode('artifactId', dep.name)
                    it.appendNode('version', dep.version)
                    it.appendNode('scope', 'provided')
                }
            }

        }
    }
}
like image 144
Piotr Kubowicz Avatar answered Oct 19 '25 00:10

Piotr Kubowicz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!