Gradle: How can I copy folder from another project in multi-project script?
Asked Answered
R

1

9

I have a multi-project script:

dependencies {
    compile '...'
    ...

    compile project(':component1')
    runtime project(':component2')
}

I need to copy folder "bin" from component1 and component2 into folder "bin" of the current project.

UPDATE: I need this to be able to "Run as"->"Run on Server" in Eclipse. Each project has Java code and Web UI files, and depends on other projects in workspace. "Deployment Assembly" does not allow copying of compiled classes from another project.

Renegado answered 15/1, 2014 at 12:46 Comment(3)
There is copy task in gradle. Configure and hook it into your build processBarratry
Is this java project?Barratry
Yes, Java Eclipse project.Renegado
B
11

I don't understand you requirement to copy folders fully.

But here custom copy task:

task copyBin(type: Copy) {
    from project(':component1').file('bin')
    into file('bin')
}

And hook into your build process:

jar.dependsOn copyBin
Barratry answered 15/1, 2014 at 19:21 Comment(3)
I don't want to hardcode dependencies in the copy task, they are already defined in "dependencies". The trick is: how to loop through dependencies in the copy task?Renegado
It is also possible - forums.gradle.org/gradle/topics/…Barratry
I tried the following: task copyProjectDependenciesToBinFolder(type: Copy) { FileCollection binFoldersFromProjectDependencies = project.configurations .collectMany { it.allDependencies } .findAll { it instanceof ProjectDependency }.file('bin') from binFoldersFromProjectDependencies into file('bin') } , but it gives me error: Cannot cast object '[]' with class 'java.util.ArrayList' to class 'org.gradle.api.file.FileCollection' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.gradle.api.file.FileCollection()Renegado

© 2022 - 2024 — McMap. All rights reserved.