ArtifactResolutionQuery to access parent poms


(uklance) #1

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 { it.selected.id }

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

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

            if (componentId instanceof ModuleComponentIdentifier) {
                File moduleDir = new File(exportDir, getPath(componentId.group, componentId.module, componentId.version))
                project.mkdir(moduleDir)
                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 { it.id.componentIdentifier }

I have a test failing here


(uklance) #2

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


(Mark Vieira) #3

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.


(uklance) #4

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?


(Mark Vieira) #5

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.


(uklance) #6

I’ve raised a feature request on github


(uklance) #7

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