I have a multi-project setup. Each project has it’s own sourceSets{main{java{srcDirs=["src/main/java"]}}
. From the :module:server
project, which also has its own sourceSet configured, I am copying source files of all other projects into one allsources
directory and then trying to build from that directory.
I made a custom JavaCompile task as an equivalent of
> cd allsources
> javac -classpath . ./com/myapp/server.java
These are the tasks I made to do above
task copyAll(type: Copy) {
from "${project.projectDir}/src/main/java"
from "${project(":module:lib1").projectDir}/src/main/java"
from "${project(":module2:lib1").projectDir}/src/main/java"
from "${project(":module2:lib2").projectDir}/src/main/java"
into "$rootProject.buildDir/allsources"
}
task compileFatJar(type: JavaCompile) {
dependsOn(copyAll)
// files(copyAll).asPath returns the path to 'allsources' directory from the copy task
source = files("${files(copyAll).asPath}")
classpath = files("${files(copyAll).asPath}")
include "${files(copyAll).asPath}/com/myapp/server.java"
// options.sourcepath = files("${files(copyAll).asPath}") // don't know how this can help
destinationDir = "$rootProject.buildDir/compiledAllSources"
}
Now when I run this it results in NO-SOURCE and does not do anything at all. How to fix this?
(I know can do a project.exec
to run javac
as the last resort)