Maven advanced: defining profiles (with module order) to make the build faster

Consider following setup:
Maven root POM
A simple project has 5 modules
<?xml version="1.0" encoding="UTF-8"?> <project> <modelVersion>4.0.0</modelVersion> <groupId>be.jochusonline</groupId> <artifactId>pom-profiles-example</artifactId> <packaging>pom</packaging> <version>0.0.1-SNAPSHOT</version> <name>PARENT</name> <modules> <module>module1</module> <module>module2</module> <module>module3</module> <module>module4</module> <module>module5</module> </modules> </project>
Maven module POM
The maven modules are looking like this (just by example). The other modules have a similar POM structure
<?xml version="1.0" encoding="UTF-8"?> <project> <modelVersion>4.0.0</modelVersion> <parent> <groupId>be.jochusonline</groupId> <artifactId>pom-profiles-example</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>pom-profiles-example-module1</artifactId> <packaging>jar</packaging> <name>MODULE1</name> </project>
Building
Building this project costs:
<a href="mailto:jochen@baileys">jochen@baileys</a> ~/Desktop/modules $ mvn clean install [INFO] Scanning for projects... [INFO] Reactor build order: [INFO] PARENT [INFO] MODULE1 [INFO] MODULE2 [INFO] MODULE3 [INFO] MODULE4 [INFO] MODULE5 [INFO] ------------------------------------------------------------------------ 8< ... >8 [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] ------------------------------------------------------------------------ [INFO] PARENT ................................................ SUCCESS [3.388s] [INFO] MODULE1 ............................................... SUCCESS [1.129s] [INFO] MODULE2 ............................................... SUCCESS [1.073s] [INFO] MODULE3 ............................................... SUCCESS [0.033s] [INFO] MODULE4 ............................................... SUCCESS [0.040s] [INFO] MODULE5 ............................................... SUCCESS [0.042s] [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6 seconds [INFO] Finished at: Tue Feb 09 18:01:54 CET 2010 [INFO] Final Memory: 16M/79M [INFO] ------------------------------------------------------------------------
... 6 seconds
Change Maven root POM to build only single module
Sometimes, in real software development processing, it's not really needed to build the whole project. Imagine the project exists of a "processing", a "web" and a "backoffice" part. You are working on the backoffice part, so why would you rebuild the web and processing part as you didn't change them?!?!
So, the improve the build process, I'm introducing profiles:
<?xml version="1.0" encoding="UTF-8"?> <project> <modelVersion>4.0.0</modelVersion> <groupId>be.jochusonline</groupId> <artifactId>pom-profiles-example</artifactId> <packaging>pom</packaging> <version>0.0.1-SNAPSHOT</version> <name>PARENT</name> <profiles> <profile> <id>all</id> <activation> <activeByDefault>true</activeByDefault> </activation> <modules> <module>module1</module> <module>module2</module> <module>module3</module> <module>module4</module> <module>module5</module> </modules> </profile> <profile> <id>module1</id> <modules> <module>module1</module> </modules> </profile> </profiles> </project>
I'm not changing anything to the modules. And I'm still able to build the project:
<a href="mailto:jochen@baileys">jochen@baileys</a> ~/Desktop/modules $ mvn clean install [INFO] Scanning for projects... [INFO] Reactor build order: [INFO] PARENT [INFO] MODULE1 [INFO] MODULE2 [INFO] MODULE3 [INFO] MODULE4 [INFO] MODULE5 [INFO] ------------------------------------------------------------------------ 8< ... >8 [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] ------------------------------------------------------------------------ [INFO] PARENT ................................................ SUCCESS [3.387s] [INFO] MODULE1 ............................................... SUCCESS [1.129s] [INFO] MODULE2 ............................................... SUCCESS [1.071s] [INFO] MODULE3 ............................................... SUCCESS [1.035s] [INFO] MODULE4 ............................................... SUCCESS [0.043s] [INFO] MODULE5 ............................................... SUCCESS [0.039s] [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6 seconds [INFO] Finished at: Tue Feb 09 18:06:37 CET 2010 [INFO] Final Memory: 16M/79M [INFO] ------------------------------------------------------------------------
Now, imagine you only want to rebuild module1. You can say to Maven: "hey, just build module 1 again" by adding: -P module1 at the commandline.
<a href="mailto:jochen@baileys">jochen@baileys</a> ~/Desktop/modules $ mvn clean install -P module1 [INFO] Scanning for projects... [INFO] Reactor build order: [INFO] PARENT [INFO] MODULE1 [INFO] ------------------------------------------------------------------------ 8< ... >8 [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] ------------------------------------------------------------------------ [INFO] PARENT ................................................ SUCCESS [3.104s] [INFO] MODULE1 ............................................... SUCCESS [1.241s] [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Tue Feb 09 18:08:46 CET 2010 [INFO] Final Memory: 15M/79M [INFO] ------------------------------------------------------------------------
So, you just won 2 seconds. Seems stupid! Yes, of course, it's just an example project with nothing in it. But in a real life situation, you can save up to 2 minutes in a build process. If you build 30 times a day, you just saved yourself ... one hour waiting for builds! ;-)
Vorige woensdag de 3e manche van het JPR clubkampioenschap gereden. Voor mij toch wel een redelijke belangrijke race. Ik hoopte vooral op een goed "karretje", want anders had ik 3 slechte wedstrijden op rij en dat zou ik niet zo tof gevonden hebben.
'k Ben al verscheidene keren met de wagen naar het buitenland gemoeten, en ik vind het altijd handig om te weten waar de flitspalen staan, en waar ze staan te flitsen. En neen, niet dat ik zo een hardrijder ben :p, maar 't is altijd handig om te weten hoe snel je waar mag :p ...
Het weekend van 22-23-24 januari ben ik samen met Sander, Nicolas, Ben, Laurent en Stijn afgezakt naar Amsterdam, meer bepaald naar de RAI.




Vandaag deze mail ontvangen in mijn mailbox van 't werk (mail werd naar alle personeelsleden gestuurd)
Google has some old URL references to my Joomla! site. I haven't deleted it yet, as people are still contacting those pages. I tried removing the links using "Webtools for Google", but it seems that Google is still picking them up :-( ...