ArtifactResolutionQuery to access parent poms

I’m writing a Gradle plugin which I’m hoping can export dependecies to a local folder for offline use. For this to be useful it needs to export jars, poms and parent poms. It’s currenty working for jars and poms but it’s not getting parent poms from the ArtifactResolutionQuery.

Here’s the code to get the poms

   private void copyPoms(Configuration config) {
        def componentIds = config.incoming.resolutionResult.allDependencies.collect { }

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

        for(component in result.resolvedComponents) {
            def componentId =

            if (componentId instanceof ModuleComponentIdentifier) {
                File moduleDir = new File(exportDir, getPath(, componentId.module, componentId.version))
                component.getArtifacts(MavenPomArtifact).each { ArtifactResult artifactResult ->
                    File pomFile = artifactResult.file
                    project.copy {
                        from pomFile
                        into moduleDir

I’ve also tried

def componentIds = config.incoming.artifacts.artifacts.collect { }

I have a test failing here

Just bumping this thread as it’s had no response for nearly a week. Hoping a Gradle guru can help

The parent pom is itself yet another component (it has it’s own group/module/version). The only way to do this I expect would be to fetch the POM for a component, parse it’s contents to find the parent, then perform another artifact resolution query on that component, and so on, recursively until you get to the root POM.

Hmm… Hasn’t gradle already done that as part of dependency resolution? Same for boms? Can I request a feature for these to be obtainable via an artifact resolution query similar to normal module poms?

Dependency resolution, yes. But an artifact query isn’t quite the same, we are simply fetching the artifacts for a given component. We are outside the context of a resolved dependency graph at this point. The resolution has already been done by this point but these two things are currently a bit disjointed. You can certainly fill a feature request on Github.

I’ve raised a feature request on github

I was able to workaround this by integrating the Maven Model Builder API with Gradle dependency management.

Commit here for anyone wanting to do similar

1 Like