Maven-ear-plugin - excluding multiple modules i.e. jars, wars etc
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 mo开发者_开发技巧dules. 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?
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.
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 (!)
i was facing a similar problem. but that was because i had a multi module project with several jars having the provided scope , i just removed the parent tag from the child ear pom , there by making it independent . and then using include to include as many jars i need.
hope this helps!!!
精彩评论