Maven in IntelliJ IDEA
This folder began with one page and one error. Starting a Maven project from IntelliJ IDEA failed with a message about a compiler plugin version that the IDE could not find, and the page that was here kept the steps that fixed it. The text of that page is the first section below; the rest of the article adds what the page could not show: the same failure from the command line, its cause, and the fix that does not depend on the IDE at all.
The error
The message was this one, and it names a plugin, a version and the word intellij at the end:
plugin 'org.apache.maven.plugins:maven-compiler-plugin:3.7.0' not found intellij
The IDE reads the pom of the project, sees that the pom pins the compiler plugin at 3.7.0, and asks its own Maven for that plugin. When the IDE has no network, or its Maven cannot reach a repository, the plugin never arrives and the import of the project stops at that message.
The steps that fix it
The following actions helped on that machine. Open the settings:
File → Settings → Build, Execution, Deployment → Build Tools → Maven
Check the box Use plugin registry. It makes the IDE read the plugin versions from Maven’s own metadata instead of a list it keeps, which is what a project that pins a version outside the IDE’s list needs.
Then clear the caches and restart:
File → Invalidate Caches / Restart
And finally run the Maven goal from the Maven tool window, Lifecycle → site → Run Maven Build. A Maven tool window that runs one goal once re-reads the project and downloads what the pom names, and the import that failed at the compiler plugin then goes through.
The same failure from mvn
The message is not an IDE bug: it is what a Maven build does when the version a pom pins is not in the repository it can reach. The same project, with the same pin, fails the same way from a terminal, and the failing command is the first phase that needs the compiler:
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>idea</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
</plugins>
</build>
</project>
src/main/java/com/example/idea/App.java
package com.example.idea;
public class App {
public static void main(String[] args) {
System.out.println("idea");
}
}
mvn -B compile > old.log 2>&1; echo "status: $?"; sed "s#$PWD#<project>#g" old.log
status: 1
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:idea >--------------------------
[INFO] Building idea 1.0.0
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for org.apache.maven.plugins:maven-compiler-plugin:jar:3.7.0 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: <TIME>
[INFO] Finished at: <TIMESTAMP>
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-compiler-plugin:3.7.0 or one of its dependencies could not be resolved:
[ERROR] Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven.plugins:maven-compiler-plugin:jar:3.7.0 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/PluginResolutionException
The POM for org.apache.maven.plugins:maven-compiler-plugin:jar:3.7.0 is missing, no dependency information available is the line the IDE turns into its own message, and Cannot access central ... in offline mode is why: the repository it would download from is out of reach. With a network, the same command downloads 3.7.0 and builds; with a local repository, the build needs a version the repository has.
The fix that works everywhere
The version in the pom is a choice, and the list of versions that work is the list the repository has. The local repository of this image has the compiler plugin at 3.13.0 and 3.15.0, and 3.15.0 is the version Maven 3.9.16 binds to the compile phase by itself. The same pom with that number builds on the command line and in the IDE, because both find the plugin:
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>idea</artifactId>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.15.0</version>
</plugin>
</plugins>
</build>
</project>
mvn -B compile > new.log 2>&1; echo "status: $?"; sed "s#$PWD#<project>#g" new.log
status: 0
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:idea >--------------------------
[INFO] Building idea 1.0.0
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.4.0:resources (default-resources) @ idea ---
[INFO] skip non existing resourceDirectory <project>/src/main/resources
[INFO]
[INFO] --- compiler:3.15.0:compile (default-compile) @ idea ---
[INFO] Recompiling the module because of <REASON>.
[INFO] Compiling 1 source file with javac [debug release 21] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: <TIME>
[INFO] Finished at: <TIMESTAMP>
[INFO] ------------------------------------------------------------------------
The general rule behind the fix: a version a project pins is a promise that the artifact is where the build looks. A machine that builds offline needs the promise kept by the local repository; a machine with a network keeps it by downloading once. Pinning nothing would also work here, because the version Maven binds is in the repository, but a project that pins nothing takes whatever Maven it runs with has, which is the problem the pin exists to solve.
The two other places where the same error appears are the errors article, which reproduces it next to two more, and the archetype article, where the versions come from a template rather than from a person.
Where to go next
Three failures and what they mean collects the errors a beginner meets with Maven, each one reproduced.
Article author: Arthur Isaev