Custom JavaCompile task on a set of files returns NO-SOURCE

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)

I saw somewhere that source property in JavaCompile can accept a single file. I removed the include and set source to server.java and it worked

task compileAll(type: JavaCompile) {
    dependsOn(copyAll)

    source = files("${files(copyAll).asPath}/com/myapp/server.java")
    classpath = files("${files(copyAll).asPath}")
    options.sourcepath = files("${files(copyAll).asPath}") // this makes it work correctly

    destinationDir = "$rootProject.buildDir/compiledAllSources"
}

and for final jar with all dependencies which were copied in one directory

task fatJar(type: Jar) {
dependsOn(compileAll)

from "$rootProject.buildDir/compiledAllSources"
include("**/*.class")
manifest.from("$projectDir/src/main/java/manifest.txt")
archiveName("server.jar")
destinationDir = file("$rootProject.buildDir/jar")

}

It’s not clear from the docs what is the difference between source and options.sourcepath. It would be helpful if someone can explain that.