【发布时间】:2014-06-11 23:22:28
【问题描述】:
我有一个 pom 文件,其中有 1 个条件依赖项和许多其他非条件依赖项(即,我希望两个配置文件都存在这些依赖项)。
条件是我是否在 tomcat 或 websphere 上进行部署,因此我已相应地命名了我的 maven 配置文件。
我的问题是,我如何才能根据我的个人资料使单个依赖项成为条件,并且两个配置文件都存在其他依赖项?
我试了一下,并在下面粘贴了我尝试过的内容,但我所尝试的内容似乎不起作用。欢迎提供一些反馈。
谢谢
<!-- tried to put the conditional dependencies in the profile section -->
<profiles>
<profile>
<id>tomcat</id>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>websphere</id>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
</profiles>
<!-- then list all other non-conditional dependencies -->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
...
...
</dependencies>
【问题讨论】:
-
您希望哪一个可用于两个配置文件?为什么不把它放在非条件依赖中?
-
不确定您所说的似乎不起作用是什么意思?您有 2 个配置文件,因此应该根据配置文件依赖项获取
标签: maven