Coach Thrasher

Thursday Oct 22, 2009

Auto-generating Maven Exclusions

Identifying maven exclusions for project dependencies can be a tedious pain in the neck of hand coding XML in the pom. My philosophy on XML is that it was not designed for hand editing: so be lazy and don't do it!... or at least try not to.

Here's my little grep/sed recipe to generate exclude statements for all top-tier dependencies of a module. I take its output and paste it into my own modules pom.xml to remove everything, except exactly what I need.


mvn dependency\:tree \
| grep "\] +- .*compile$" \
| sed "s/^\[INFO\] +- \([a-zA-Z0-9\._-]*\):\([a-zA-Z0-9\._-]*\):.*$/<exclusion><groupId>\1<\/groupId><artifactId>\2<\/artifactId><\/exclusion>/g" \
| sort

And here's what it spit out for something including the kitchen sink of dependencies:

<exclusion><groupId>com.adobe.acrobat</groupId><artifactId>acrobat</artifactId></exclusion>
<exclusion><groupId>commons-httpclient</groupId><artifactId>commons-httpclient</artifactId></exclusion>
<exclusion><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId></exclusion>
<exclusion><groupId>javax.jcr</groupId><artifactId>jcr</artifactId></exclusion>
<exclusion><groupId>javax.mail</groupId><artifactId>mail</artifactId></exclusion>
<exclusion><groupId>log4j</groupId><artifactId>log4j</artifactId></exclusion>
<exclusion><groupId>org.apache.jackrabbit</groupId><artifactId>jackrabbit-core</artifactId></exclusion>
<exclusion><groupId>org.apache.jackrabbit</groupId><artifactId>jackrabbit-ocm</artifactId></exclusion>
<exclusion><groupId>org.apache.lucene</groupId><artifactId>lucene-core</artifactId></exclusion>
<exclusion><groupId>org.apache.ws.security</groupId><artifactId>wss4j</artifactId></exclusion>
<exclusion><groupId>org.hibernate</groupId><artifactId>hibernate</artifactId></exclusion>
<exclusion><groupId>org.springframework</groupId><artifactId>spring-core</artifactId></exclusion>
<exclusion><groupId>org.springframework</groupId><artifactId>spring</artifactId></exclusion>
<exclusion><groupId>org.springmodules.jcr</groupId><artifactId>springmodules-jcr</artifactId></exclusion>
<exclusion><groupId>rome</groupId><artifactId>itunes-com-podcast</artifactId></exclusion>
<exclusion><groupId>rome</groupId><artifactId>rome</artifactId></exclusion>
<exclusion><groupId>xalan</groupId><artifactId>xalan</artifactId></exclusion>

How do you do the same thing?

Comments:

Post a Comment:
Comments are closed for this entry.

Calendar

Feeds

Search

Links

Navigation

Referrers