1

Having two Gradle projects projectA and projectB where projectA is a dependency of projectB, i.e., my build.gradle of projectB contains:

dependencies {
   compile(project(':projectA'))
} 

How can I copy the source code from projectA into projectB before the java build task runs?

1 Answers1

0

You can create a custom copy task that copies the source code from project A to project B.

task copyProjectA(type: Copy) {
    from project(":projectA").projectDir.toString() + "/src/main/java"
    into project.projectDir.toString() + "/destination"
}

tasks.compileJava.dependsOn += copyProjectA

I have a difficult time understanding why you'd want to do that though.

Raniz
  • 10,882
  • 1
  • 32
  • 64
  • Do you know how I can create a source jar in projectA and copy this into destination of projectB? –  Apr 28 '15 at 08:53
  • 1
    You can have a task depend on tasks in other projects: `task copyProjectA(type: Copy, dependsOn: project(":projectA").tasks.sourceJar) {` – Raniz Apr 28 '15 at 08:57
  • See [here](http://stackoverflow.com/questions/11474729/how-to-build-sources-jar-with-gradle) for how to build a source JAR. – Raniz Apr 28 '15 at 08:57