Maven连接Nexus遇PluginResolutionException及连接失败,如何解决?
Hey there, let's work through this PluginResolutionException and Nexus connection issue step by step! First off, I spotted a tiny but critical typo in your ~/.m2/settings.xml snippet that might be throwing things off—let's start there, then cover other common fixes.
1. Fix the Obvious Typo in Settings.xml
Your config has <severs> instead of <servers>—this misspelled tag will prevent Maven from recognizing your Nexus server authentication details entirely. Correct it to:
<servers> <server> <id>Releases</id> <username>deployment</username> <password>test1234</password> </server> <!-- Add your other server config here if incomplete --> </servers>
2. Ensure Nexus Repository & Mirror Configurations Are Complete
PluginResolutionException usually happens when Maven can't find a source for plugins. You need to make sure Maven knows to use your Nexus instance for both dependencies and plugins:
Add a Mirror in settings.xml
This tells Maven to route all central repository requests through your Nexus:
<mirrors> <mirror> <id>nexus-mirror</id> <mirrorOf>central</mirrorOf> <url>http://your-nexus-url/repository/maven-public/</url> </mirror> </mirrors>
Add a Profile with Repository & Plugin Repository
Make sure Maven has access to Nexus plugin repositories, and link the repo ID to your server auth ID:
<profiles> <profile> <id>nexus-profile</id> <repositories> <repository> <id>Releases</id> <url>http://your-nexus-url/repository/maven-releases/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>false</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>Releases</id> <url>http://your-nexus-url/repository/maven-releases/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>false</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus-profile</activeProfile> </activeProfiles>
Note: The <id> values here must match exactly with the <id> in your <server> config—this is how Maven maps authentication to the repository.
3. Verify Nexus Connection & Permissions
- Manually visit your Nexus repository URL in a browser to confirm it's reachable.
- Check that your
deploymentuser has read permissions for the Maven releases repository in Nexus (you can set this in Nexus's user role settings). - Test the connection with verbose Maven logging to see exactly what's happening:
Themvn clean install -U -X-Uflag forces dependency updates, and-Xprints detailed logs—look for lines about repository connections or authentication failures.
4. Clean Local Maven Cache
Corrupted local cache files can also cause resolution issues. Clear the cache and rebuild:
rm -rf ~/.m2/repository
Then run your build command again to let Maven re-download everything from Nexus.
If you still hit issues after these steps, share a snippet of the verbose log from the mvn clean install -X command, and we can dig deeper!
内容的提问来源于stack exchange,提问作者박지훈

