Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 576
mes5k Avatar asked Nov 02 '10 22:11

mes5k


People also ask

How do I run maven archetype in eclipse?

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.

How do I know my maven project archetype?

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.

What is maven Quickstart archetype?

maven-archetype-quickstart is an archetype which generates a sample Maven project: project. |-- pom.

How do I run an archetype in maven?

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.


1 Answers

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.)

like image 113
Partly Cloudy Avatar answered Sep 19 '22 00:09

Partly Cloudy