简体   繁体   English

Maven卡在旧版本的系统依赖项上

[英]Maven stuck on old version of system dependency

My Maven project has a dependency on a non-Maven library, which is coded as a system dependency: 我的Maven项目具有对非Maven库的依赖关系,该库被编码为系统依赖关系:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>foo</artifactId>
  <version>${foo.version}</version>
  <scope>system</scope>
  <systemPath>${foo.jar}</systemPath>
</dependency>

where the location of the library can be controlled via local properties: 可以通过本地属性控制库的位置:

<properties>
  <foo.version>2.1.1</foo.version>
  <foo.basedir>/usr/local</foo.basedir>
  <foo.libdir>${foo.basedir}/lib</foo.libdir>
  <foo.jar>${foo.basedir}/java/foo-${foo.version}.jar</foo.jar>
</properties>

Recently, the library switched from version 2.1.1 to version 2.2.0, so I changed the foo.version property, but Maven seems to be stuck on the old version: 最近,该库从2.1.1版切换到了2.2.0版,因此我更改了foo.version属性,但是Maven似乎停留在旧版本上:

...
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) com.example:foo:jar:2.1.1
...

I have run mvn dependency:purge-local-repository (many times, actually). 我已经运行了mvn dependency:purge-local-repository (实际上很多次)。 The string 2.1.1 does not appear anywhere in my POM, profiles.xml , or settings.xml . 字符串2.1.1不会出现在我的POM, profiles.xmlsettings.xml任何位置。 Still, every time I try to build my project, Maven fails with the above error. 尽管如此,每次我尝试构建项目时,Maven都会因上述错误而失败。

What's going on here? 这里发生了什么? Where is Maven storing the dependency version information and how can I update it? Maven在哪里存储依赖项版本信息,如何更新它?

I think the ${foo.version} might be getting resolved as a filter property. 我认为${foo.version}可能会被解析为过滤器属性。 Can you check the properties file under src/main/filters . 您可以检查src/main/filters下的属性文件吗?

Not sure if this is indeed the problem but just give it a try and update back. 不知道这是否确实是问题,只需尝试一下并更新即可。

The other reason that I could think of is - there might be a transitive dependency on com.example:foo:jar:2.1.1 . 我想到的另一个原因是-可能对com.example:foo:jar:2.1.1有传递依赖。 That is some other dependency which needs 2.1.1 version of this artifact. 那是其他一些依赖,需要此工件的2.1.1版本。 You can find which artifact is bringing this transitively by doing mvn dependency:tree 您可以通过执行mvn dependency:tree来找到哪个工件带来了传递mvn dependency:tree

Dependency version conflict is a very common problem and most of the time when we start building our application, we never focus or generally we forgot on that aspect until and unless our application starts behaving in an unexpected way or getting started some exception. 依赖版本冲突是一个非常普遍的问题,在大多数时候,我们开始构建应用程序时,除非我们的应用程序开始以意外的方式运行或开始出现某些异常,否则我们从不关注或通常忘记了这一方面。

For readers and visitors of SO who are interested in knowing the reason why dependency conflicts arises and how we can avoid them in our application , I found a source here explained in a precise way ,so i thought of adding my 2 bits to it . 对于SO的读者和来访者,他们有兴趣了解发生依赖冲突的原因以及如何避免在应用程序中发生冲突,我在这里找到了一个源代码,它以一种精确的方式进行了解释,因此我想在其中添加2位。

http://techidiocy.com/maven-dependency-version-conflict-problem-and-resolution/ http://techidiocy.com/maven-dependency-version-conflict-problem-and-resolution/

Cheers 干杯

You know what. 你知道吗。 Seeing the workaround that @Chris Conway found, I think that this might have been "solved" by simply running mvn clean . 看到@Chris Conway发现的解决方法后,我认为可以通过简单地运行mvn clean “解决”该问题。

And even if it would not have helped here, it is always worth trying mvn clean when something strange happens. 即使在这里没有帮助,当发生奇怪的事情时,也总是值得尝试使用mvn clean

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

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