The errors a beginner meets

Four failures cover most of what goes wrong in the first week with Gradle. Each one is reproduced below with the build script that causes it and the message it prints, so the message can be recognised instead of guessed at.

An unknown plugin

settings.gradle

rootProject.name = 'shop'

build.gradle

plugins { id 'com.github.johnrengelman.shadow' version '8.1.1' }

The plugin is not one of Gradle’s own, so Gradle looks for it in the Plugin Portal, which this offline container cannot reach. Three sources are named in the message, because those are the three places Gradle looks:

gradle tasks --console=plain --offline --no-daemon > build.log 2>&1; sed "s#$PWD#<project>#g" build.log


FAILURE: Build failed with an exception.

* Where:
Build file '<project>/build.gradle' line: 2

* What went wrong:
Plugin [id: 'com.github.johnrengelman.shadow', version: '8.1.1'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:8.1.1')
  Searched in the following repositories:
    Gradle Central Plugin Repository

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights from a Build Scan (powered by Develocity).
> Get more help at https://help.gradle.org.

BUILD FAILED in 10s

The fix is a version that exists and a repository that has it, or a plugin that is a core plugin. Here neither is possible offline, which is why the error is the lesson: a plugin id and a version are resolved before any task runs, and a typo in either one reads exactly like this.

A dependency that is not there

build.gradle

plugins { id 'java' } repositories { mavenCentral() } dependencies { implementation 'com.google.guava:guava:33.4.0-jre' }

src/main/java/com/example/App.java

package com.example; import com.google.common.base.Joiner; public final class App { public static void main(String[] args) { System.out.println(Joiner.on(", ").join("a", "b")); } }

gradle compileJava --console=plain --offline --no-daemon > build.log 2>&1; sed "s#$PWD#<project>#g" build.log


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava' (registered by plugin class 'org.gradle.api.plugins.JavaBasePlugin').
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve com.google.guava:guava:33.4.0-jre.
     Required by:
         root project 'shop'
      > No cached version of com.google.guava:guava:33.4.0-jre available for offline mode.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights from a Build Scan (powered by Develocity).
> Get more help at https://help.gradle.org.

BUILD FAILED in 11s
1 actionable task: 1 executed

The message names the configuration, the module and the reason. A network would have answered; offline, the answer is that the module is not in a repository this build can read. In a project the usual fixes are a repositories block that names the repository of the artifact and a version that exists there.

A release the JDK does not know

build.gradle

plugins { id 'java' } java { sourceCompatibility = JavaVersion.VERSION_25 targetCompatibility = JavaVersion.VERSION_25 }

The build asks for Java 25 and the JDK of this machine is 21. Gradle accepts the number in the script — it is a constant of the API — and the compiler refuses it:

gradle compileJava --console=plain --offline --no-daemon > build.log 2>&1; sed "s#$PWD#<project>#g" build.log


[Incubating] Problems report is available at: file://<project>/build/reports/problems/problems-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava' (registered by plugin class 'org.gradle.api.plugins.JavaBasePlugin').
> Compiler initialization failed
    error: invalid source release: 25

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights from a Build Scan (powered by Develocity).
> Get more help at https://help.gradle.org.

BUILD FAILED in 11s
1 actionable task: 1 executed

invalid source release: 25 is the whole diagnosis: the compiler of JDK 21 cannot produce class files of a newer version, whatever the build script says. The fix is a release the JDK supports, or a toolchain that points at a JDK 25 installation.

A compile error

build.gradle

plugins { id 'java' }

src/main/java/com/example/App.java

package com.example; public final class App { public static void main(String[] args) { System.out.println("shop") } }

gradle compileJava --console=plain --offline --no-daemon > build.log 2>&1; sed "s#$PWD#<project>#g" build.log


<project>/src/main/java/com/example/App.java:5: error: ';' expected
        System.out.println("shop")
                                  ^
1 error

[Incubating] Problems report is available at: file://<project>/build/reports/problems/problems-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava' (registered by plugin class 'org.gradle.api.plugins.JavaBasePlugin').
> Compilation failed; see the compiler output below.
  <project>/src/main/java/com/example/App.java:5: error: ';' expected
          System.out.println("shop")
                                    ^
  1 error

* Try:
> Check your code and dependencies to fix the compilation error(s)
> Run with --scan to get full insights from a Build Scan (powered by Develocity).

BUILD FAILED in 12s
1 actionable task: 1 executed

The compiler message, the caret under the position and the count are printed twice: once by the compiler and once in the What went wrong block, which is what a log reader greps for. The task is the one that failed, and every task that depends on it did not run.

Related

Article author: Arthur Isaev