我有一个项目,它有一些特殊的源文件夹,具体取决于我们的客户,我们现在要使用 Maven,所以我有一些问题......
我想知道指定每个构建将使用哪些源的正确方法是否是为每个客户端定义一个特殊的配置文件,并且每个配置文件将有一个模块,其中将定义所有特定于客户端的源:
<profiles>
<profile>
<id>client1</id>
<modules>
<module>modules/client1</module>
</modules>
</profile>
</profiles>
我需要一些可以描述为:“好的,如果客户端是 client1,则附加此源文件夹,如果客户端是 client2,则附加此其他文件夹”。有没有办法将 Maven 配置为“附加”源文件夹?因为看起来我们可以覆盖build-helper-maven-plugin。
此外,如果我添加模块中的所有源,我的路径就会出现问题,因为我需要将源文件夹定义为 <source>../../WEB-INF/src</source
我所有的测试都变得一团糟,这似乎是一个解决方法。我需要一些线索来了解设计结构的简洁方法。
[编辑] 我的文件夹结构是这样的:
myApp/plugin1/src
myApp/plugin2/src
myApp/pluginN/src
myApp/WEB-INF/generalSrc
myApp/pom.xml
myApp/clients/myclient1/plugin1/src
myApp/clients/myclient1/plugin2/src
myApp/clients/myclient1/pom.xml
myApp/clients/myclient2/plugin1/src
myApp/clients/myclient2/pom.xml
所以我想避免使用像 <source>../../WEB-INF/generalSrc
这样的东西
最佳答案
我建议为子模块创建一个父模块:
App
ear-module
pom.xml
module1
pom.xml
module2
pom.xml
module3
pom.xml
...
pom.xml
然后选择一个或多个要按配置文件构建的模块:
<profile>
<id>client1</id>
<modules>
<module>ear-module</module>
<module>module1</module>
...
</modules>
</profile>
要仅在目标包模块中包含必要的模块,即ear-module(或war),请创建具有相同ID的配置文件,类似于:
<profile>
<id>client1</id>
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>module1</artifactId>
<version>...</version>
<type>ejb or jar</type>
</dependency>
</dependencies>
…
<profile>
第二步更重要,但第一步可以节省您构建未使用模块的时间。
关于java - Maven:配置文件 + 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32957618/