How do you generate a POM dependency reference to the non-default artifact in a lib project?


#1

I have two Java projects ‘projA’ and ‘projB’. ‘projA’ generates 2 artifacts. The default artifact is named ‘projA-1.0.jar’. The secondary artifact is named ‘projAsub-1.0.jar’. The ‘projAsub’ artifact has its own unique configuration called ‘confSub’.

The problem I have is that ‘projB’ depends on the ‘confSub’ configuration of ‘projA’ (which is deployed with the ‘artifactID’ equal to ‘projAsub’)

dependencies { compile project( path:':projA', configuration:'confSub') }

But when the POM is generated for ‘projB’ it sets the artifactId to ‘projA’, instead of ‘projAsub’.

What is the correct way to setup ‘projB’ so that it generates a POM with a dependency to ‘projAsub’ instead of ‘projA’?


#2

To make things clearer, I found a way to hack the POM to get the result I wanted. I’m hoping there is a better way:

publishing {
    publications {
        java(MavenPublication) {
            from components.java
            pom.withXml {
                def depNode = asNode().dependencies.dependency.find {
                    it.artifactId[0].text() == 'projA' }
                depNode.artifactId[0].setValue('projAsub')
            }
        }
    }
}