英文:
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:
<dependency>
<groupId>com.foo</groupId>
<artifactId>foo</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论