Sunday, 4 September 2011

Maven Archetype Plugin 2.1 very useful feature

Maven Archetype Plugin 2.1 has just been released and contains a very (IMHO) useful feature.
Usually when you use this plugin with generate goal, you have a very huge list of available archetypes (a non human readable list :-) ).

mvn archetype:generate
here the output :
.....
444: remote -> se.vgregion.javg.maven.archetypes:javg-minimal-archetype (-)

Yes around 450 possible archetypes. Do you have configured enough scrolling in your console to review all ?: -).
So now with 2.1 release it's possible to apply some filtering :

  • with a mojo parameter

  • in the prompt


You can filter on the groupId and/or the artifactId.
The documentation is available here.
My bad !. The official documentation has a typo.
You must read : mvn archetype:generate -Dfilter=org.apache:struts (and not mvn archetype:generate -Dorg.apache:struts).
So this feature is pretty cool to reduce the archetypes list when you know a part of what type of project type you want to create.
A sample, you want to create a gwt project.
So simply use :

mvn archetype:generate -Dfilter=:gwt
The output list is reduce :
Choose archetype:
1: remote -> net.kindleit:gae-archetype-gwt (-)
2: remote -> net.sf.mgp:maven-archetype-gwt (An archetype which contains a sample Maven GWT project.)
3: remote -> org.codehaus.mojo:gwt-maven-plugin (Maven plugin for the Google Web Toolkit.)
4: remote -> org.codehaus.sonar.archetypes:sonar-gwt-plugin-archetype (-)
5: remote -> org.geomajas:geomajas-gwt-archetype (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :

Note you can enter an other filter to reduce the list

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : maven
Choose archetype:
1: remote -> net.sf.mgp:maven-archetype-gwt (An archetype which contains a sample Maven GWT project.)
2: remote -> org.codehaus.mojo:gwt-maven-plugin (Maven plugin for the Google Web Toolkit.)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :


You can filtering on groupId.
I want an artifact with gwt coming from codehaus :

mvn archetype:generate -Dfilter=org.codehaus:gwt
The output list :
Choose archetype:
1: remote -> org.codehaus.mojo:gwt-maven-plugin (Maven plugin for the Google Web Toolkit.)
2: remote -> org.codehaus.sonar.archetypes:sonar-gwt-plugin-archetype (-)


Have Fun !

Apache Maven, Maven, Apache are trademarks of The Apache Software Foundation.

1 comment:

ehsavoie said...

There have been some progress also with properties depending on other properties but what I miss the most is the possibility to use velocity to manipulate properties (capitalize where are you ? ) ;o)