I've created a few archetypes for a project that work fine for now, but I'd like to be able to verify that the code generated from the archetypes continues to work in the future.
What I'd like is a phase of the archetype build that takes the archetype just created, runs mvn archetype:generate
on it, and then runs mvn verify
on the generated code to verify that the generated code is actually OK. If need be I'll write my own mojo to do this, but wanted to see if a solution already exists. I see the archetype:integration-test
goal, but it doesn't seem to be doing what I want.
first via the File New Other Maven Maven Project entry. On the archetype selection, select the maven-archetype-webapp entry and click the Next button. Enter the group, artifact and version of your new Maven component.
Archetype configurationYou can see the packaging maven-archetype . You can customize build of your archetype here as with any other pom. However, there is another pom. xml file located under src\main\resources\archetype-resources which is the pom file of the generated project.
maven-archetype-quickstart is an archetype which generates a sample Maven project: project. |-- pom.
To create an archetype manually, we can start with a newly created Maven project and then we can add the resources mentioned above. Or, we can generate it by using the archetype-maven-plugin, and then customize the content of the archetype-resources directory and archetype-metadata. xml file.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With