Gradle ":compileJava NO-SOURCE" - Wrong Source Layout in CI
Gradle found no Java sources to compile, so :compileJava reported NO-SOURCE and produced an empty artifact. The sources are not under the path Gradle expects for the source set, or the wrong project was built.
What this error means
The build succeeds but the jar is empty or missing classes; the log shows > Task :app:compileJava NO-SOURCE. Downstream steps fail because no classes were produced.
> Task :app:compileJava NO-SOURCE
> Task :app:jar
> Task :app:build
BUILD SUCCESSFUL
# but app.jar contains no .class filesCommon causes
Sources not under the expected sourceSet path
Gradle compiles src/main/java by default. Code under a different directory (e.g. java/ or source/) is not seen unless the sourceSet is configured.
Wrong subproject targeted
Running :app:build when the code lives in a different module compiles nothing in :app, yielding NO-SOURCE.
How to fix it
Point the sourceSet at the real directory
Configure the main sourceSet if your code is not in the default location.
sourceSets {
main {
java {
srcDirs("src/main/java", "generated/java")
}
}
}Verify the project and sources
- Run
./gradlew projectsto confirm the module names. - Run
./gradlew :app:javaToolchainsand checksrc/main/javaactually contains sources. - Target the correct subproject path in the build command.
How to prevent it
- Keep sources under the conventional
src/main/javalayout (or declare sourceSets explicitly), and target the correct subproject.