views:

553

answers:

2

I've been using the Maven EAR plugin for creating my ear files for a new project. I noticed in the plugin documentation you can specify exclude statements for modules. For example the configuration for my plugin is as follows...

  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.4.1</version>
        <configuration>
            <jboss>
                <version>5</version>
            </jboss>
            <modules>
                <!-- Include the templatecontroller.jar inside the ear -->
                    <jarModule>
                        <groupId>com.kewill.kdm</groupId>
                        <artifactId>templatecontroller</artifactId>
                        <bundleFileName>templatecontroller.jar</bundleFileName>
                        <includeInApplicationXml>true</includeInApplicationXml>
                    </jarModule>
                    <!-- Exclude the following classes from the ear -->
                    <jarModule>
                       <groupId>javax.activation</groupId>
                       <artifactId>activation</artifactId>
                       <excluded>true</excluded>
                    </jarModule>
                    <jarModule>
                   <groupId>antlr</groupId>
                   <artifactId>antlr</artifactId>
                   <excluded>true</excluded>
                </jarModule>
                ... declare multiple excludes
                <security>
                    <security-role id="SecurityRole_1234">
                        <role-name>admin</role-name>
                    </security-role>
                </security>
            </configuration>
        </plugin>
    </plugins>

This approach is absolutely fine with small projects where you have say 4-5 modules to exclude. However, in my project I have 30+ and we've only just started the project so as it expands this is likely to grow.

Besides explicitly declaring exclude statements per module is it possible to use wildcards or and exclude all maven dependencies flag to only include those modules i declare and exclude everything else? Is anyone aware of a more elegant solution?

A: 

Not sure about whether wildcards are supported, but it is very simple to write your own mojo. You could wrap the existing mojo and then take some arbitrary config of your own design, such as your wildcard syntax.

Better still, you could submit your mojo to the maven team (!)

James B
BTW, apologies, it's absolutely typical of Stackoverflow, you ask a specific question and someone posts an answer that is sorta/kinda related but it invariably involves more work!
James B
Also, I have a bit of example code for a custom mojo, if you don't get any other answers that give you the out-of-the-box config
James B
I've written mojo's before I was just hoping to avoid doing that because as usual we have a tight deadline ;) Anyway you're probably right the plugin isn't advanced enough to allow for wildcards or full exclusion of other modules. Most likely I'll have to in the end write up a plugin myself. In the time being I'll just manually exclude the modules I need. Thanks.
James Murphy
A: 

Besides explicitly declaring exclude statements per module is it possible to use wildcards or and exclude all maven dependencies flag to only include those modules I declare and exclude everything else?

The maven-ear-plugin doesn't provide this feature out-of-box (and I don't think that it would be easy to configure anyway, an ear must be packaged very precisely). However, what's not clear here is how you get the dependencies you need to exclude. Depending on your answer, there could be several ways to handle them:

  • You could maybe declare some of them as optional if they are dependencies of your artifacts to avoid to retrieve them transitively.
  • You could maybe mark some dependencies as "provided" (and put them in a parent pom, redeclare only what you want in the POM of the EAR).

Hard to answer without seeing the whole picture though.

Pascal Thivent