Gradle copy Dependencies .jar along with .pom

Hi Team, I am using copyAllDependencies in gradle 7.6 like below

task copyAllDependencies(type: Copy) {
configurations.default.resolvedConfiguration.resolvedArtifacts.forEach { ResolvedArtifact artifact →
project.copy {
def groupPath = (‘.’,‘/’)
def fileName =
def fileVersion =
from artifact.file
into ‘target/upload/dependency-jars/’+groupPath+‘/’+fileName+‘/’+fileVersion



Is there anyway we can also copy “.pom” files along with “.jar” files ?

Your task has several problems, starting with not using task-configuration avoidance which does not make it incorrect, just wasting your time when running a build that should not execute that task,

up to the task always being up-to-date as you do not copy anything anywhere at execution time, but on the other hand always doing the copy already in the configuration phase even if that task will not even be executed as you use project.copy in the configuration phase of the task instead of configuring the task so that it can do the copying at execution time.

But to answer your actual question, iirc you need to use an ArtifactResolutionQuery to get the POM file for a dependency. But actually that will also only partly help, because POM files also often have parent POM files and those will not be downloaded alongside automatically, …

@Vampire Thanks for the suggestions and solution!

1 Like