Maven中的两种依赖关系版本 [英] two versions of dependencies in maven
问题描述
有没有一种方法可以传递命令开关来更改我的依赖关系?
is there a way where i can pass a command switch to change my dependencies?
意思是,我有
<dependency>
<groupId>api</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
并将其设置为如果我这样做
and set it up in such a way where if i do
mvn软件包-已提供
mvn package -Dprovided
我的有效POM为
<dependency>
<groupId>nmsc</groupId>
<artifactId>nmsc_api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency>
在不使用配置文件作为配置文件的情况下,我需要将依赖项放入两次.这可能吗?
without using profiles as profiles require me to put the dependencies in twice. is this possible?
推荐答案
如果将配置文件与变量配对,则使用配置文件不需要您多次列出依赖项,尽管如果只是针对单个属性执行此操作,那么也许您应该直接覆盖属性:
Using profiles doesn't require you to list the dependencies multiple times if you pair it with variables, though if you're just doing that for a single property, then maybe you should just override a property directly:
<properties>
<myExeScope>compile<myExeScope>
</properties>
<dependencies>
<dependency>
<groupId>nmsc</groupId>
<artifactId>nmsc_api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<scope>${myExeScope}</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>${myExeScope}</scope>
</dependency>
</dependencies>
然后,您应该能够覆盖指定依赖项的范围:
Then you should be able to override the scope of the specified dependencies:
mvn -DmyExeScope=provided
请注意,我尚未对此进行编译,因此,如果有错别字,请更正它们并记录下更正.
Note, I haven't compiled this, so if there are typos please correct them and note the correction.
这篇关于Maven中的两种依赖关系版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!