Friday, February 7, 2014

Maven Archetypes ++

When I'm trying out code samples I find it useful to create Maven archetypes. I find it useful to create maven modules that have all properties set in parent project. This saves me time when trying out code from chapters that have a lot of examples whit similar configurations.

This link explains a lot, but I have few additions.

  1. If you'r using Eclipse (STS) to create archetype you should take care not to use embedded maven.
  2. After you create archetype with mvn archetype:create-from-project you should edit pom.xml in target/generated-sources/archetype
    1. Change version so it won't be SNAPSHOT
    2. Adjust name, artifactId and description.
  3. You should also brows sub-directories to see if there are hidden files there (.settings/, .projec or .classpath). You should remove this files.
  4. You should also check pom.xml in target/generated-sources/archetype/src/main/resources/archetype-resources/ to see if there are any problems there.
Only when your satisfied with state of your project should you run mvn install from target/generated-sources/archetype/.

If you' using Eclipse tu create new project with newly created archetype, make sure that you select Default Local as catalog, and if you didn't remove SNAPSHOT from version you should check Include snapshot archetypes checkbox.