6

I am trying to create a new maven project using the maven-archetype-quickstart archetype, which incorporates a AppTest.java sample test class and a dependency for Junit version 3.8.1 but I would like to use Junit 4.

How can I change Junit version on the quickstart maven archetype?

Roberto Linares
  • 2,215
  • 3
  • 23
  • 35
  • I figured I wasn't the only person in the world who thought this must have done by someone else already. Did you find a different maven archetype out there on central with JUnit4? I would also like it to specify Java 8 in the `maven-compiler-plugin` config. – Adam Jun 29 '16 at 10:15

3 Answers3

1

Use the prompt or a terminal in eclipse and do this :

      mvn -B archetype:generate \
     -DarchetypeGroupId=org.apache.maven.archetypes \
     -DgroupId=com.mycompany.app \
     -DartifactId=my-app

After that you have to import it from Eclipse, IntelliJ or Netbeans as a maven project and you'll got the version of J-Unit 4.X

Hohenheim
  • 1,545
  • 1
  • 12
  • 28
1

Apparently, other people also had an issue with this junit version shipped with maven-archetype-quickstart so they filed a Jira issue, which was solved in the archetype version 1.2.

Since that version is not in the default Maven Archetype Catalog, the next task is to find an archetype catalog with the maven-archetype-quickstart 1.2 version and use that catalog for your mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeCatalog=http://your.updated.catalog command.

EDIT: Apparently, according to this answer, you can also create your custom archetype based on a project's POM and then install it in your local archetype catalog.

Community
  • 1
  • 1
Roberto Linares
  • 2,215
  • 3
  • 23
  • 35
0

You should be able to change the version in pom.xml

See this article for in-depth explanation: https://examples.javacodegeeks.com/enterprise-java/maven/junit-maven-example/

Indigo8
  • 590
  • 1
  • 4
  • 10
  • 2
    That is the thing. I want to change the way the archetype is generated, so it automatically adds junit 4 instead of 3.8.1 so I don't have to change the pom.xml every time I create a new project. – Roberto Linares Mar 29 '16 at 06:26