Maven与Nexus Repository集成配置问题求助
Hey there, let's work through why your Maven build is still pulling from the central repository instead of your Nexus maven_ub repo. Here are step-by-step checks and fixes to resolve this:
1. Verify Which settings.xml Maven is Actually Using
Maven prioritizes the user-specific settings file over the global one in most cases. The user settings are located at C:\Users\<YourUsername>\.m2\settings.xml, while you modified the global one at C:\Program Files\apache-maven-3.3.9\conf\settings.xml.
- Run this command to see the effective settings Maven is applying:
mvn help:effective-settings - Look for the
<mirrors>section in the output. If your Nexus mirror isn't listed, Maven is loading a differentsettings.xml. You can either:- Update the user-specific
settings.xmlwith your mirror configuration, or - Force Maven to use your modified global settings by running builds with:
mvn clean install -s "C:\Program Files\apache-maven-3.3.9\conf\settings.xml"
- Update the user-specific
2. Confirm Your Nexus Repository Configuration
Your maven_ub repo needs to be set up correctly to proxy the central repository:
- Log into your Nexus admin panel and check if
maven_ubis a Proxy Repository (not a Hosted repository). Hosted repos only store local artifacts and won't pull from central. - Ensure the proxy repository is configured to point to Maven Central (default URL:
https://repo.maven.apache.org/maven2/) and that the repository status shows as Online. - Test if you can access the repo directly via browser:
http://1.2.3.4:8081/repository/maven_ub/— you should see the repository's directory structure.
3. Adjust the mirrorOf Scope
Your current <mirrorOf>central</mirrorOf> only mirrors the official central repo. If your project uses other repositories (like Spring's repo, for example), Maven will bypass your Nexus mirror to pull from those.
- To mirror all repositories (a common setup for internal Nexus usage), change the value to:
Note: If you have local or specialized repos that shouldn't be mirrored, you can exclude them with syntax like<mirrorOf>*</mirrorOf><mirrorOf>*,!local-repo</mirrorOf>.
4. Clear Maven Local Repository Cache
Maven might be using cached dependencies from your local repo instead of fetching from Nexus.
- Delete the relevant dependency folders in
C:\Users\<YourUsername>\.m2\repository, or - Run your build with the
-Uflag to force dependency updates:mvn clean install -U
5. Check for Repository Configurations in Your Project's pom.xml
If your project's pom.xml includes explicit <repositories> or <pluginRepositories> sections, these can override the mirror settings in settings.xml.
- Open your project's
pom.xmland look for these sections. If they exist, either:- Remove them to rely on your Nexus mirror, or
- Ensure your
mirrorOfconfiguration covers these repos (using<mirrorOf>*</mirrorOf>as mentioned earlier).
内容的提问来源于stack exchange,提问作者Shalika

