Skip to content
Latchkey

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.

gradle output
> Task :app:compileJava NO-SOURCE
> Task :app:jar
> Task :app:build
BUILD SUCCESSFUL
# but app.jar contains no .class files

Common 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.

build.gradle.kts
sourceSets {
    main {
        java {
            srcDirs("src/main/java", "generated/java")
        }
    }
}

Verify the project and sources

  1. Run ./gradlew projects to confirm the module names.
  2. Run ./gradlew :app:javaToolchains and check src/main/java actually contains sources.
  3. Target the correct subproject path in the build command.

How to prevent it

  • Keep sources under the conventional src/main/java layout (or declare sourceSets explicitly), and target the correct subproject.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →