Copy project dependecies from maven repository


(John Hanrahan) #1

I have a multi project setup where some subprojects have dependencies to jar files in the local maven repository. After the project is built, all the jar files are copied to an installation directory using a copy task, but this includes only the subproject artefacts.

Root project build.gradle:

File destDir = project.file('dest')

subprojects {
  dependencies {
    repositories {
      mavenLocal()
      maven { url '/some/path' }
    }
  }
}

task myCopy(type: Copy, dependsOn: subprojects.jar) {
  from(subprojects.jar)
  into project.file(destDir)
}

Subproject build.gradle

dependencies {
  compile project(':aaa')
  compile project(':bbb')

  compile group: 'com.example', name: 'foo-bar', version: '1.2.0'
}

Is there a way to also copy all the jar file dependencies (foo-bar-1.2.0.jar in this example) from the maven repository?

Thanks in advance!


(Louis Jacomet) #2

By simply accessing the configurations, you will get a copy of all transitive dependencies, not only external, but projects as well:

task myCopy(type: Copy, dependsOn: subprojects.jar) {
  from(subprojects.jar)
  // The following will add foo-bar but also the jars for aaa and bbb
  from subprojects.configurations.compile
  into project.file(destDir)
}

If you only need the external dependencies and not the project one, the easiest will be to split the project and external dependencies between different configurations.