简体   繁体   English

Maven 无法解析正确的 SNAPSHOT 依赖项

[英]Maven does not resolve correct SNAPSHOT dependencies

I will be quick.我会很快的。 My maven version is 3.5.0.我的 Maven 版本是 3.5.0。 I'm using some libraries in my web applications.我在我的 Web 应用程序中使用了一些库。 The libraries are installed separately and deployed in an artifactory instance.这些库单独安装并部署在工件实例中。

I have the following pom (part of):我有以下 pom(部分):

<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:但在库中,Maven 把这个库:

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

instead of this:而不是这个:

process.domain.common-0.0.1-SNAPSHOT.jar process.domain.common-0.0.1-SNAPSHOT.jar

My dependencies are resolved from artifactory.我的依赖项是从 artifactory 解决的。 Why does Maven put this temporary library with timestamp name instead of the SNAPSHOT?为什么 Maven 将这个临时库放在时间戳名称而不是 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:解决方法是在war项目的pom.xml中添加maven war插件:

<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:没有 war 插件的 WEB-INF/lib:

WEB-INF/lib with the war plugin:带有war 插件的 WEB-INF/lib:

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

If you build a Snapshot locally, it is just build with the name 0.0.1-SNAPSHOT .如果您在本地构建一个快照,它只是使用名称0.0.1-SNAPSHOT构建。 If you deploy it to Artifactory, it gets an internal timestamp version number like the one you mentioned.如果你将它部署到 Artifactory,它会得到一个内部时间戳版本号,就像你提到的那样。

When you download it again, Artifactory gives you the latest timestamp.当您再次下载时,Artifactory 会为您提供最新的时间戳。

So locally, you sometimes have a -SNAPSHOT version and sometimes a timestamp version.所以在本地,你有时有一个-SNAPSHOT版本,有时有一个时间戳版本。 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.我不清楚战争中的工件如何命名的确切规则,但是无论您是否有时间戳版本,都应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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