定义Maven依赖版本在运行之前。

huangapple go评论67阅读模式
英文:

Define Maven dependency version just before runtime

问题

所以我有一个依赖项:

<dependency>
    <groupId>com.foo</groupId>
    <artifactId>foo</artifactId>
    <version>2.4</version>
    <scope>provided</scope>
</dependency>

我需要这个依赖项在某些时候是版本2.4,在其他时候是版本2.2。有没有办法在运行时之前选择它将运行的版本,或者也许有一个Maven命令可以这样做?

而且,考虑到范围是"provided",如果我只将版本设置为2.2,那么当提供2.4版本时,它会工作吗?

英文:

So I have a dependency:

&lt;dependency&gt;
			&lt;groupId&gt;com.foo&lt;/groupId&gt;
			&lt;artifactId&gt;foo&lt;/artifactId&gt;
			&lt;version&gt;2.4&lt;/version&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;

I need this dependency to be in version 2.4 at some times and at 2.2 at other times. Is there a way to choose just before runtime which version it's going to run, or maybe a maven command to do so?

And given the scope is provided, if I just set the version to 2.2, when provided with the 2.4 version will it work?

答案1

得分: 4

不,没有办法做到这一点。

即使您确实走上动态类加载的道路,问题仍然存在,您将会有两个版本的库,它们会以您不希望的方式相互竞争和/或冲突。

主要问题在于,您似乎希望在2.2中使用一些在2.4中不可用的功能。我会强烈鼓励您考虑迁移到2.4并更新您的代码,使其与2.4更好地配合,而不必经历这种痛苦。

英文:

No, there is no way to do this.

Even if you did walk down the path of dynamic class loading, the problem remains that you would have two versions of a library that would compete and/or conflict with one another in ways you don't desire.

The main issue here is that you seem to want some features in 2.2 that aren't available in 2.4. I would strongly encourage you instead to look at what it would take to migrate to 2.4 and update your code so that it behaves better with 2.4 instead of having to go through this pain.

huangapple
  • 本文由 发表于 2020年8月8日 00:11:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63305537.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定