Jenkins构建Maven项目时Nexus依赖解析失败问题求助
Let's break down how to diagnose and fix this issue step by step, since you're running all core services (Jenkins, Nexus) in Docker containers and working with the OpenShift Tasks repo for your CD demo:
Verify network connectivity between Jenkins and Nexus containers
First, confirm Jenkins can reach your Nexus instance. Exec into the Jenkins container withdocker exec -it <jenkins-container-name> /bin/bash, then run:ping <nexus-container-name>(if they're on the same Docker network, container names should resolve automatically)curl http://<nexus-host>:<nexus-port>/repository/maven-public/to check if the repository endpoint is accessible.
If either fails, make sure both containers are attached to the same custom Docker network (create one if needed withdocker network create demo-networkand re-run containers attached to it).
Check Maven settings.xml configuration in Jenkins
Ensure Jenkins is using a Maven settings.xml that correctly points to your Nexus repository:- In Jenkins, go to Manage Jenkins > Global Tool Configuration > Maven > Maven installations, and confirm you've specified a custom settings.xml path (or configure it per job under Build > Advanced > Settings file).
- Your settings.xml should include valid mirror and profile configurations for Nexus, like this example:
<mirrors> <mirror> <id>nexus</id> <mirrorOf>central</mirrorOf> <url>http://<nexus-host>:<nexus-port>/repository/maven-public/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
If Nexus requires authentication, add a
<servers>block with the correct username and password matching your Nexus user.Confirm the missing artifact exists in Nexus
Log into your Nexus web UI, use the search bar to look for the artifact specified in the error (copy the exact groupId, artifactId, version from your POM's import statement).- If it's a third-party dependency: Ensure your Nexus has a proxy repository for Maven Central, and this proxy is included in the
maven-publicgroup repository. - If it's a custom internal artifact: Make sure it was deployed to Nexus correctly (e.g., via
mvn deployfrom your local machine or a pre-build pipeline).
- If it's a third-party dependency: Ensure your Nexus has a proxy repository for Maven Central, and this proxy is included in the
Validate the OpenShift Tasks POM configuration
Double-check the<dependencyManagement>section in your project's POM where the import is defined. Ensure the coordinates (groupId,artifactId,version) match exactly what's stored in Nexus—typos here are a super common culprit.Check Docker DNS resolution
If you're using container names to reference Nexus in your Maven settings, ensure Docker's internal DNS is working reliably. As a quick test, replace the container name with Nexus's static IP address (find it withdocker inspect <nexus-container-name> | grep IPAddress) in your settings.xml to bypass potential DNS issues.Verify Jenkins build command settings
In your Jenkins job configuration, make sure the Maven build command includes the correct settings file if you're not using the global one. For example:mvn clean install -s /var/jenkins_home/.m2/settings.xml
内容的提问来源于stack exchange,提问作者John Seen

