Jenkins构建Maven项目失败:非快照依赖从Apache Snapshots拉取报错
Hey, let's break down what's going on here and how to fix this frustrating build failure.
First, let's parse the error message clearly
08:47:42 [ERROR] Failed to execute goal on project DataAdapterFB1: Could not resolve dependencies for project joy.com:DataAdapterFB1:jar:1.0.0: Failed to collect dependencies at org.java-websocket:java-websocket:jar:1.3.0: Failed to read artifact descriptor for org.java-websocket:java-websocket:jar:1.3.0: Could not transfer artifact org.java-websocket:java-websocket:pom:1.3.0 from/to apache-snapshots (http://139.69.2.40:8081/nexus/content/repositories/apache-snapshots): Failed to transfer file: http://139.69.2.40:8081/nexus/content/repositories/apache-snapshots/org/java-websocket/java-websocket/1.3.0/java-websocket-1.3.0.pom. Return code is: 400 , ReasonPhrase:Repository version policy: SNAPSHOT does not allow version: 1.3.0. -> [Help 1]
The core issue here is straightforward:
- Your project is trying to pull the non-snapshot version 1.3.0 of
java-websocket - Maven is first checking the
apache-snapshotsrepository (which only allows SNAPSHOT versions) - That repository rejects the request with a 400 error, since 1.3.0 isn't a SNAPSHOT build
Why does this work locally but fail on Jenkins?
- Your local Maven cache already has the
java-websocket1.3.0 artifact, so it doesn't need to hit the remote repository - Or your local
settings.xmlhas a different repository order that prioritizes non-snapshot repositories first - The recent changes to snapshot repository enabled status/update policies likely altered Maven's dependency resolution flow on Jenkins
Fixes you can implement right away
1. Reorder your repositories (most direct fix)
Maven resolves dependencies in the order repositories are declared in your POM. Move all non-snapshot repositories (central, thirdparty, releases) above the apache-snapshots repository so Maven checks valid sources for stable versions first:
<repositories> <repository> <id>central</id> <url>http://139.69.2.40:8081/nexus/content/repositories/central</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>thirdparty</id> <url>http://139.69.2.40:8081/nexus/content/repositories/thirdparty</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>releases</id> <url>http://139.69.2.40:8081/nexus/content/repositories/releases</url> <snapshots> <enabled>false</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <!-- Move snapshot-only repositories to the bottom --> <repository> <id>apache-snapshots</id> <url>http://139.69.2.40:8081/nexus/content/repositories/apache-snapshots</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>snapshot</id> <url>http://139.69.2.40:8081/nexus/content/repositories/snapshots</url> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories>
2. Explicitly disable releases for the apache-snapshots repository
Even if you don't reorder, you can tell Maven to never look for stable releases in the apache-snapshots repo by adding a releases block:
<repository> <id>apache-snapshots</id> <url>http://139.69.2.40:8081/nexus/content/repositories/apache-snapshots</url> <snapshots> <enabled>true</enabled> </snapshots> <!-- Add this line to block release artifacts --> <releases> <enabled>false</enabled> </releases> </repository>
Do the same for the apache-snapshots entry in pluginRepositories to avoid similar issues with plugin dependencies.
3. Check Jenkins' global Maven settings
Jenkins might be using a global settings.xml that has a different repository order or configuration than your local machine. Go to Manage Jenkins > Global Tool Configuration, find your Maven installation, and check the path to its settings file. Verify that non-snapshot repositories are prioritized there too.
4. Temporary cache cleanup
If Jenkins' local Maven cache has corrupted or partial artifacts, manually delete the org/java-websocket directory in Jenkins' Maven repo (usually at ~/.m2/repository/org/java-websocket) and trigger a rebuild.
Verification step
After making changes, run mvn clean install -U locally to confirm the build works without hitting the snapshot repo for stable dependencies, then push to Jenkins to verify the fix holds.
内容的提问来源于stack exchange,提问作者Tacitus86

