Yves
Yves

Reputation: 172

Maven profiles in modules

I have a Maven Java EE project with several modules.

PROJECT
 --EJB
 --WEB1
 --WEB2
 --EAR

Now I want to create a profile which compile and include WEB1 and one profile which include both

To exclude/include the module from the build, I include the wanted sub-modules in the main pom.xml according to the selected profile. This works fine.

The problem is the dependencies in the EAR module.

How do I exclude either the module WEB1 or WEB2. Redefine the profiles part don't work.

The question is: Is there a way to control the dependencies in a module of a project, according to the selected profile

EDIT:

My fault, I have create the tags in the instead as direct in the root

Upvotes: 0

Views: 3973

Answers (1)

Marek Gregor
Marek Gregor

Reputation: 3851

Exclusion of modules based on profiles is not possible, but inclusion works with usage of special feature 'combine.children' since maven 3.0.2, described in http://www.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/

So you have to define minimal content of EAR as default and with profiles add dependencies/modules in following way in your ear module:

<project ....>
    ...
    <name>EAR</name>
    ...
    <dependencies>
        <dependency>EJB</dependency> // specify groupId, artifactId, version, type ...
        <dependency>WEB1</dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>build-with-WEB2</id>
            <dependencies>
                <dependency>WEB2</dependency> // specify groupId, artifactId, version, type ...
            </dependencies>
            <build>
                <plugins>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-ear-plugin</artifactId>
                    <version>${maven-ear-plugin.version}</version>
                    <configuration>
                        <modules combine.children="append">
                            <webModule>
                                <groupId>...</groupId>
                                <artifactId>WEB2</artifactId>
                                <bundleFileName>WEB2.war</bundleFileName>
                                ...
                            </webModule>
                        </modules>
                    </configuration>
                </plugins>
            </build>
        </profile>
    </profiles>
    <build>
        ...
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>${maven-ear-plugin.version}</version>
                <configuration>
                    ...
                    <modules>
                        <ejbModule>
                            <groupId>...</groupId>
                            <artifactId>EJB</artifactId>
                            <bundleFileName>EJB.jar</bundleFileName>
                            ...
                        </ejbModule>
                        <webModule>
                            <groupId>...</groupId>
                            <artifactId>WEB1</artifactId>
                            <bundleFileName>WEB1.war</bundleFileName>
                            ...
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Upvotes: 4

Related Questions