Maven:配置文件+模块

Maven: Profiles + Modules

我有一个项目有一些特殊的源文件夹,具体取决于我们的客户,我们现在要使用 maven,所以我有一些问题...

我想知道指定每个构建将使用哪些源的正确方法是为每个客户定义一个特殊的配置文件,并且每个配置文件都有一个模块,其中将定义所有客户特定的源:

<profiles>
    <profile>
        <id>client1</id>
        <modules>
            <module>modules/client1</module>
        </modules>
    </profile>
</profiles>

我需要一些可以描述为:“好的,如果客户端是 client1,则附加此源文件夹,如果客户端是 client2,则附加其他文件夹”。有没有办法将 Maven 配置为 "attach" 源文件夹?因为看起来我们可以覆盖 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>

第二步更重要,但第一步可以节省您构建未使用模块的时间。