Three failures and what they mean
Four failures cover most of what stops a Maven build before it compiles anything. Each one is reproduced here on the same small project, in full, with the line to read and the change that fixes it. All four are repository or version problems, and none of them is about the Java code.
The project
A pom with nothing in it but the release, and one class. The failures below change one thing at a time; the base pom is this one.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>errors</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
</properties>
</project>
src/main/java/com/example/errors/App.java
package com.example.errors;
public class App {
public static void main(String[] args) {
System.out.println("errors");
}
}
A plugin that is not there
The first is a goal whose plugin the repository does not have. Anything outside the plugins of the lifecycles will do, and the enforcer plugin is a common one to reach for:
mvn -B enforcer:enforce > plugin.log 2>&1; echo "status: $?"; sed "s#$PWD#<project>#g" plugin.log
status: 1
[INFO] Scanning for projects...
[WARNING] Plugin not found in any plugin repository: org.apache.maven.plugins:maven-enforcer-plugin
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: <TIME>
[INFO] Finished at: <TIMESTAMP>
[INFO] ------------------------------------------------------------------------
[ERROR] Error resolving version for plugin 'org.apache.maven.plugins:maven-enforcer-plugin' from the repositories [local (<HOME>/.m2/repository), central (https://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginVersionResolutionException
Plugin not found in any plugin repository: org.apache.maven.plugins:maven-enforcer-plugin is the whole diagnosis. The prefix enforcer was found in the metadata of the plugin groups, so Maven knows the artifact name, and the artifact itself is nowhere it can look: not in the local repository, and the settings are offline. The last line gives the exception, PluginVersionResolutionException.
The fix is a version the repository has, or a network. Nothing about the project is wrong, which is why this one is worth recognising: it looks like a broken pom and it is an empty repository. The plugins article explains the prefix resolution behind the message.
A release the JDK does not have
The second is a compiler release newer than the JDK. The property becomes --release 25, the compiler plugin runs, and javac refuses:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>errors</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>25</maven.compiler.release>
</properties>
</project>
mvn -B compile > release.log 2>&1; echo "status: $?"; sed "s#$PWD#<project>#g" release.log
status: 1
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.example:errors >-------------------------
[INFO] Building errors 1.0.0
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.4.0:resources (default-resources) @ errors ---
[INFO] skip non existing resourceDirectory <project>/src/main/resources
[INFO]
[INFO] --- compiler:3.15.0:compile (default-compile) @ errors ---
[INFO] Recompiling the module because of <REASON>.
[INFO] Compiling 1 source file with javac [debug release 25] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: <TIME>
[INFO] Finished at: <TIMESTAMP>
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.15.0:compile (default-compile) on project errors: Fatal error compiling: error: release version 25 not supported -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Fatal error compiling: error: release version 25 not supported is the compiler’s own message, wrapped by the plugin into a failed goal. The release of this JDK is 21, and the plugin passes the number through without checking it: the JDK is the one that knows which releases it has. Either the property goes down to a release the JDK has, or the build runs on a newer JDK.
A dependency that cannot be resolved
The third is a dependency the repository does not have. Mockito is the library a Java project reaches for next, and it is not in the seed of this image:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>errors</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.14.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
mvn -B test > dependency.log 2>&1; echo "status: $?"; sed "s#$PWD#<project>#g" dependency.log
status: 1
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------< com.example:errors >-------------------------
[INFO] Building errors 1.0.0
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for org.mockito:mockito-core:jar:5.14.2 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: <TIME>
[INFO] Finished at: <TIMESTAMP>
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project errors: Could not resolve dependencies for project com.example:errors:jar:1.0.0
[ERROR] dependency: org.mockito:mockito-core:jar:5.14.2 (test)
[ERROR] Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.mockito:mockito-core:jar:5.14.2 has not been downloaded from it before.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Could not resolve dependencies for project com.example:errors:jar:1.0.0 comes before any compile: Maven resolves the graph first. The two lines under it name the artifact, its scope and the repository it could not reach, which is the same pair of facts as the plugin failure one section up, in a different exception: DependencyResolutionException.
The fix is the same shape: a version the repository has, or a network. A project that cannot change the version can exclude the dependency instead, which the exclusions section shows, but a dependency the code calls cannot be excluded.
A parent that cannot be found
The fourth is a pom whose parent is a published artifact that has not been published yet. A child with an empty <relativePath/> does not look next door, and the resolver has nowhere else to go:
child/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>errors</artifactId>
<version>1.0.0</version>
<relativePath/>
</parent>
<artifactId>child</artifactId>
</project>
cd child
mvn -B validate > parent.log 2>&1; echo "status: $?"; sed "s#$PWD#<project>#g" parent.log
status: 1
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:child:1.0.0: The following artifacts could not be resolved: com.example:errors:pom:1.0.0 (absent): Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact com.example:errors:pom:1.0.0 has not been downloaded from it before. and 'parent.relativePath' points at no local POM @ line 7, column 11
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.example:child:1.0.0 (<project>/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.example:child:1.0.0: The following artifacts could not be resolved: com.example:errors:pom:1.0.0 (absent): Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact com.example:errors:pom:1.0.0 has not been downloaded from it before. and 'parent.relativePath' points at no local POM @ line 7, column 11 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
Non-resolvable parent POM for com.example:child:1.0.0, and the end of the line explains both halves: the artifact com.example:errors:pom:1.0.0 has not been downloaded and 'parent.relativePath' points at no local POM. The pom of a parent is an artifact like any other, and it is installed by mvn install of the parent, or found by ../pom.xml when the element is left out.
Three fixes, in the order a project tries them: install the parent (mvn -B install in its folder, which writes the pom into the local repository), drop the <relativePath/> if the parent is one folder up, or point <relativePath> at a path of its own. The parent article shows the working case.
How to read them
All four logs share a shape, and the shape is the point:
- The first line that starts with [ERROR] after BUILD FAILURE names the goal or the project and the cause.
- The exception at the end of that line says which layer failed: PluginVersionResolutionException for a plugin whose version cannot be found, PluginResolutionException for a plugin whose jar cannot be downloaded, DependencyResolutionException for a dependency, ProjectBuildingException for a pom that cannot be read and MojoFailureException or MojoExecutionException for a goal that ran and failed.
- The -> [Help 1] link at the end of every line points at the page of that exception on the Maven wiki, which names the usual causes.
- The log never says "check your code": a failure before the first compile is about the pom, the repository and the versions, and a failure inside a goal names the goal and the file.
-e adds the stack trace of the exception and -X the debug log; the switches article shows what the second one adds. Neither changes the first line, which is the one to read first.
Where to go next
The last article builds a small library from its pom to its tests and its jar, end to end, with every command of the course in one place.
Article author: Arthur Isaev