Use the ArtifactResolutionQuery API to get parent pom

(Niklas Walter) #1

Hi Folks,

I try to access the parent POM of a Maven Module via the ArtifactResolutionQuery API.
Therefore I query the POM file of the module and then parse the POM for a parent element.
When found I build a ModuleComponentIdentifier with the corresponding coordinates of the parent.
Unfortunatley the Query API is not able to resolve the MavenPomArtifact of this new component.

My code for retrieving the parent pom is

void resolveParentPom(File pomFile) {
    def pom = new XmlParser().parse(pomFile)
    if (!pom.parent) {
    def identifier = new MavenPomComponentIdentifier(
            group: pom.parent.groupId.text(),
            module: pom.parent.artifactId.text(),
            version: pom.parent.version.text()

    def result = project.dependencies.createArtifactResolutionQuery().forComponents(identifier)
            .withArtifacts(MavenModule, MavenPomArtifact)

    result.resolvedComponents.each { component ->
        ModuleComponentIdentifier id =
        component.getArtifacts(MavenPomArtifact).each { ResolvedArtifactResult artifact ->
            // Do something useful
            println artifact

the class MavenPomComponentIdentifier is:

class MavenPomComponentIdentifier implements ModuleComponentIdentifier {

    String group
    String module
    String version

    String getDisplayName() {
        return "$group:$module:$version"

Am I missing something, or is it just not possible to query artifacts of pom-only modules?