Solve the problem that maven cannot download the dependent jar package

Posted by bluedot on Mon, 02 Dec 2019 18:42:27 +0100

Background:

There is a maven private server built in the company, and a core jar package has been made. At the beginning, it was XXX core.1.0.0.snapshot version, which can be used normally in both local and project environments. In order to support the launch and release a stable version, XXX core.1.0.0.jar.

The local compilation is normal, the startup is normal, the project environment is normal, and when gitlab is automatically deployed to the Rancher after submission, it is found that the jar package cannot be downloaded all the time.

repository configuration of pom.xml file:

<repositories>
        <repository>
            <id>xxxxx.releases</id>
            <name>Releases</name>
            <url>https://nexus.xxxxxx.com/repository/maven-releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>xxxxxx.snapshots</id>
            <name>Snapshot</name>
            <url>https://nexus.huilianyi.com/repository/maven-snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
</repositories>

 

When compiling, maven reports an error:

Failed to execute goal on project service: Could not resolve dependencies for project com.xxxxx:service:war:1.0-SNAPSHOT: Failure to find com.xxxxx-core:jar:1.0.0 in https://nexus.xxxx.com/repository/maven-releases was cached in the local repository, resolution will not be reattempted until the update interval of xxx.releases has elapsed or updates are forced -> [Help 1]

The prompt means that the id of the private Repository: xxx.releases has a cache update interval. Before the update time, the jar is obtained from the cache. Therefore, the jar package uploaded to the repository xxx-core.1.0.0.jar is not in the cache

So it wasn't pulled down.

terms of settlement:

pom.xml is changed to:

<repositories>
        <repository>
            <id>xxxxx.releases</id>
            <name>Releases</name>
            <url>https://nexus.xxxxxx.com/repository/maven-releases</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>xxxxxx.snapshots</id>
            <name>Snapshot</name>
            <url>https://nexus.huilianyi.com/repository/maven-snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
</repositories>                    
The < updatepolicy > tag is the update policy, and always is the latest dependency in the download warehouse.
Note: after pulling down, remove this configuration, or you will download the jar package every time, which is very time-consuming to compile.

Topics: Java Maven nexus snapshot xml