MarcosTonina
MarcosTonina

Reputation: 361

Maven: Profiles + Modules

I have a project that has some special source folders depending of our clients and we are now going to maven, so I have some questions...

I was wondering if a correct approach to specify which sources will go with each build is defining a special profile for each client, and each profile will have a module in which all client-specific sources will be defined:

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

I need something that could be described as: "Ok, if the client is client1, attach this source folders, if client is client2 attach this other folders". Is there a way to configure Maven to "attach" source folders? Because it seems like we can just override build-helper-maven-plugin.

In addition, if I add all the sources in the module I have a problem with my paths, because I need to define my source folders as <source>../../WEB-INF/src</source and all my tests go into a mess and it seems like that is a workaround. I need some clues to learn about clean approaches to design my structure.

[Edit] My folder structure is like this:

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

So I want to avoid using things like <source>../../WEB-INF/generalSrc

Upvotes: 0

Views: 2297

Answers (1)

puczo
puczo

Reputation: 727

I suggest to create a parent for a child modules:

App  
  ear-module
    pom.xml
  module1    
    pom.xml  
  module2 
    pom.xml  
  module3  
    pom.xml 
  ...
pom.xml

Then choose one or more modules to be build by profile:

<profile>
   <id>client1</id>
   <modules>
      <module>ear-module</module>
      <module>module1</module>
       ...
   </modules>
</profile>

To include only necessary modules in the target package module i.e. ear-module (or war), create profile with the same id similar to:

<profile>
  <id>client1</id>
  <dependencies>
    <dependency>
        <groupId>...</groupId>
        <artifactId>module1</artifactId>
        <version>...</version>
        <type>ejb or jar</type>
    </dependency>                   
   </dependencies>
   …
<profile>

The second step is more important, but the first will save you time building unused modules.

Upvotes: 1

Related Questions