是否可以在maven pom.xml文件中为不同的配置文件使用不同的依赖项集?
EG
mvn -P debug
mvn -P release
我想在一个配置文件中选择一个不同的依赖jar文件,该配置文件具有相同的类名和相同接口的不同实现。
引用Maven documentation on this:
A profile element contains both an optional activation (a profile trigger) and the set of changes to be made to the POM if that profile has been activated. For example, a project built for a test environment may point to a different database than that of the final deployment. Or dependencies may be pulled from different repositories based upon the JDK version used.
(重点是我的)
只需将release
配置文件的依赖项放在配置文件声明本身中,并对debug
执行相同操作。
<profiles> <profile> <id>debug</id> … <dependencies> <dependency>…</dependency> </dependencies> … </profile> <profile> <id>release</id> … <dependencies> <dependency>…</dependency> </dependencies> … </profile> </profiles>
您的groupId,artifactId应该在配置文件中标记为属性,您可以将依赖项移动到通用部分。