speed up your build by stripping unneeded plugins from the reactor

Ian Springer ian.springer at redhat.com
Sat Feb 13 01:23:49 UTC 2010


RHQ now includes 40 or so plugins, which is awesome. However, if you are 
an RHQ developer, the large number of plugins can lower your 
productivity for a few reasons:

1) Building 40 plugins makes a mvn install from the project root take 
longer.
2) Deploying 40 plugins makes the startup of the RHQ Server take longer.
3) Some newer plugins that are not yet stable can cause issues that 
affect the entire Agent JVM (heap leaks, permgen leaks, JVM crashes due 
to misbehaved native code, etc.).

For 90% of my everyday development, I only need a handful of plugins, so 
I wanted an easy way to only build (and dev-deploy) only those plugins 
whenever I ran mvn from the project root or from modules/plugins/. 
Thanks to the new profile deactivation capability added in Maven 2.0.10, 
I found a way to do it:

1) In modules/plugins/pom.xml, I split out all but a few essential 
plugins (platform, rhq-agent, and jmx) into profiles (jboss-plugins, 
linux-plugins, etc.), grouping similar plugins. These profiles are 
activated by default by activating them if the java.home sysprop is set 
(which it always is). So if you just run 'mvn install', all 40 plugins 
are built, as they were before. Here's what it looks like:

<modules>
<!--  core plugins  -->
<module>platform</module>
<module>rhq-agent</module>
<module>jmx</module>
</modules>

<profiles>

<profile>
<id>jboss-plugins</id>
<activation>
<property>
<name>java.home</name>
</property>
</activation>

<modules>
<!--  NOTE: Order is important. -->
<module>augeas</module>
<module>apache</module>
<module>tomcat</module>
<module>jboss-as</module>
<module>hibernate</module>
<module>rhq-server</module>
<module>jboss-cache</module>
<module>jboss-as-5</module>
<module>jboss-cache-v3</module>
<!--  was not in Jopr build at merge time <module>jbossOSGi</module>  -->
</modules>
</profile>

<profile>
<id>linux-plugins</id>
<activation>
<property>
<name>java.home</name>
</property>
</activation>

<modules>
<module>augeas</module>
<module>cron</module>
<module>script</module>
<module>script2</module>
<module>grub</module>
<!-- not behaving <module>hardware</module> -->
<module>hosts</module>
<module>cobbler</module>
<module>sudoers</module>
<module>hudson</module>
<module>netservices</module>
<module>perftest</module>
<module>samba</module>
<module>postfix</module>
<module>aliases</module>
<module>sshd</module>
<module>virt</module>
<module>kickstart</module>
</modules>
</profile>

<profile>
<id>misc-plugins</id>
<activation>
<property>
<name>java.home</name>
</property>
</activation>

<modules>
<module>iis</module>
<module>database</module>
<module>postgres</module>
<module>hudson</module>
<!-- error in code generation (see RHQ-1225) <module>jira</module> -->
<module>mysql</module>
<!-- non-public dependency <module>onewire</module> -->
<module>oracle</module>
<module>perftest</module>
<module>snmptrapd</module>
<module>twitter</module>

<!-- bundle plugins -->
<module>filetemplate-bundle</module>
</modules>
</profile>

<profile>
<id>validate-plugins</id>
<activation>
<property>
<name>java.home</name>
</property>
</activation>

<modules>
<!-- make this the last - it will validate all the plugins -->
<module>validate-all-plugins</module>
</modules>
</profile>

</profiles>


2) When running mvn, deactivate the plugin profiles that I don't want 
using the Maven 2.0.10+ syntax, e.g.:

mvn -P'!linux-plugins' -P'!misc-plugins' -P'!validate-plugins'

This will build only the core plugins (platform, rhq-agent, and jmx) and 
the jboss plugins (12 plugins instead of 40!). To pass these options by 
default whenever mvn is run, I can define a shell alias in my .profile 
as follows:

alias mvn="mvn -P'!linux-plugins' -P'!misc-plugins' -P'!validate-plugins'"

That's it. No more plugin overload!

The great part about this solution is that things still work as they did 
before if you just run 'mvn install' and don't know about this trick.

I hope this will save others as much time as I know it will save me.

--Ian


P.S. I'd like to use the same trick to change the build so 'mvn install' 
will build the container by default (i.e. so newbies won't need to know 
to run 'mvn install -Penterprise' in order to build the full 
distribution). Then everyday developers who want to run mvn from the 
project root and skip building the container can do:

mvn -P'!container'

or add that option to their mvn alias.



More information about the rhq-devel mailing list