Skip to content
Advertisement

Is there a maven repository to quickstart Java 11 app

There is a quickstart maven archetype for Java 7, as I can see here: https://maven.apache.org/archetypes/maven-archetype-quickstart/ The problem with this is when I fire this command:

JavaScript

Enter project directory and fire this command:

JavaScript

I get this error:

JavaScript

Please note that there is some problem with my JDK install, as update-alternatives tells me that I am running JDK 11:

JavaScript

But, when I run java -version, it gives me this:

JavaScript

I am not sure why I am not getting OpenJDK 11, despite the fact that I installed JDK 11 only in the first place. Maybe will start a different thread on that.

Advertisement

Answer

tl;dr

The quickstart archetype, sadly, is often out-of-date.

Update your maven-surefire-plugin element of your POM to the latest version such as 3.0.0-M7.

Update your dependencies to current version

Oddly, the maven-archetype-quickstart artifact is never kept up-to-date. It lists dependencies with old versions that may not work well with the latest versions of Java, your IDE, or other libraries.

This is quite frustrating, as you would think the artifact would be kept up-to-date via some automated scripting. After all, the entire point of Maven is to make this kind of configuration chore easy and automated!

Fortunately, you can easily update the version numbers yourself.

How do you know what is the latest version number to enter for each dependency?

  • You can look up manually the latest version number using the web site of a Maven repository. Copy-paste the version number to your POM.
  • You can let your IDE (IntelliJ, NetBeans, etc.) suggest the latest number as you edit the version number XML element value. You may or may not to type some “help-me” keystroke depending on how your IDE works. Before doing this, be sure to update your IDE’s cache of Maven repository data so it knows the current latest version numbers. For example, in IntelliJ go to preferences, and in the search field for settings, type repo, and in the list of known repositories click each Update button.

Steps

First, if using your IDE to work with Maven, be sure to update its cache of Maven repository data so you are getting the latest quickstart artifact. For example, in IntelliJ, Preferences > Build, Execution, Deployment > Build tools > Maven > Repositories > Update button.

enter image description here

The initial POM should expand into a bigger one. You may need a Maven clean and install.

After first use, go through your POM.

JavaScript

On each element in the POM, change the version number to the latest.

Your IDE may assist by showing you a list of version numbers it knows of.

enter image description here

Or use a Maven repository web site to verify the latest version number. Like this:

enter image description here

You may find most of the items are out-of-date. In particular, regarding the surefire problem described in the Question, change the surefire element to v3.

JavaScript

This will fix your surefire specifically, in my experience. Some problems were recently fixed in later versions. I don’t recall the nature of the problems, perhaps related to the Java Platform Module System.

My version of the POM after updating to the latest as of 2019-05-29.

JavaScript

JUnit

Notice I also updated JUnit from v4 to the vastly improved v5 “Jupiter”. If you do this, you will also need to update the AppTest.java file to simply change the import lines.

Old:

JavaScript

New:

JavaScript

Lastly, do a Maven clean and install to get those latest versions of your dependencies actually installed inside your app.

By the way, for more about JUnit Jupiter, and how to run old JUnit 3 & 4 testes, see my Answer to another Question.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement