How can I test a maven archetype that I've just created?

UPDATE 2013: This is now much easier than the other answers suggest.

https://issues.apache.org/jira/browse/ARCHETYPE-334 was completed in Aug 2011

To use, simply place the word install inside the goal.txt file mentioned above, and the tests from the project you are archetyping will be invoked as part of a normal build. (And/or verify in the case of OP.)

However, if you new to making archetypes be aware that this popular mini-guide is out of date and, while it will work for making an archetype it will not work for having archetype integration tests run. You should instead be creating an archetype-metadata.xml file as described here. (This is much nicer to work with as well, as it uses file sets!)

Also note these integration tests do not respond to -DskipTests but this can be remedied as follows:

<build>
  <plugins>

    <plugin>
      <artifactId>maven-archetype-plugin</artifactId>
      <version>2.2</version>
      <configuration>
        <skip>${skipTests}</skip>
      </configuration>        
    </plugin>

  </plugins>
</build>

(Although this looks like it skips the entire plugin, it actually works, probably because it falls back to a legacy mode; whereas I could not find any successful way to skip just the integration-test goal execution using code above.)


beside the the approach of using the maven-invoker-plugin, we are using a different approach. With the help of the Maven Verifier you can test your maven plugins and archetypes easily. Just add the following dependency into your pom of your maven test project:

<dependency>                                
  <groupId>org.apache.maven.shared</groupId>
  <artifactId>maven-verifier</artifactId>   
  <version>1.2</version>                    
</dependency>                               

Now you are able to use

org.apache.maven.it.Verifier

into your normal JUnit Tests. With the verifier you can run maven goals and some assertions about the result. For a complete example just check out the integration test maven modules of our javascript-archetypes: https://github.com/akquinet/javascript-archetypes


I was struggling a little with this myself, and figured that when using current v2.3 of the maven-archetype-plugin, in addition to a src/test/resources/projects/first/goal.txt, one also needs a src/test/resources/projects/first/archetype.properties containing something like this:

sourceEncoding=UTF-8
groupId=integrationtest.group
artifactId=integrationtest.artifactId
version=1.0.0-SNAPSHOT
package=org.eclipse.xtend.xtend-archetype.integrationtest
packageInPathFormat=org/eclipse/xtend/xtend-archetype/integrationtest

This pull request illustrates a complete working example.