简体   繁体   中英

Maven does not resolve correct SNAPSHOT dependencies

I will be quick. My maven version is 3.5.0. I'm using some libraries in my web applications. The libraries are installed separately and deployed in an artifactory instance.

I have the following pom (part of):

<project>
  ....
  <properties>
    <process.domain.common.version>0.0.1-SNAPSHOT</process.domain.common.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.intersoft</groupId>
        <artifactId>process.domain.common</artifactId>
        <version>${process.domain.common.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.intersoft</groupId>
      <artifactId>process.domain.common</artifactId>
    </dependency>
  </dependencies>
</project>

but in the libs, Maven puts this library:

process.domain.common-0.0.1-20190319.151024-3.jar

instead of this:

process.domain.common-0.0.1-SNAPSHOT.jar

My dependencies are resolved from artifactory. Why does Maven put this temporary library with timestamp name instead of the SNAPSHOT? This behavior does not happen in all resolved libraries.

Finally, i found the solution.

The solution is to add maven war plugin in your pom.xml of the war project:

<properties>
   <version.war.plugin>2.5</version.war.plugin>
</properties>

<build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>${version.war.plugin}</version>
                <configuration>
                    <warName>${project.artifactId}</warName>
                </configuration>
            </plugin>
        </plugins>
    </build>

Proof:

WEB-INF/lib without the war plugin:

WEB-INF/lib with the war plugin:

Maven 将当前日期附加到快照以比较本地存储库中的快照版本和远程存储库中的快照版本,并评估是否需要下载远程 jar,因为今天下载 0.0.1-SNAPSHOT 可能会提供与昨天下载不同的文件或者明天。

If you build a Snapshot locally, it is just build with the name 0.0.1-SNAPSHOT . If you deploy it to Artifactory, it gets an internal timestamp version number like the one you mentioned.

When you download it again, Artifactory gives you the latest timestamp.

So locally, you sometimes have a -SNAPSHOT version and sometimes a timestamp version. The exact rule how the artifact in the war is named is unclear to me, but whether you have timestamped version or not, you should be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM