Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Maven archetype "quickstart" in Java 10?

Tags:

When I create a new IntelliJ 2018.1 project from the Maven archetype maven-archetype-quickstart version 1.3 using Oracle 10.0.1 on macOS Sierra, I get this error when doing a Maven install.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project h2e2: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test failed.: NullPointerException -> [Help 1]

I am running this directly after creating the new project. I am writing no code. I can run the default line:

    public static void main( String[] args ) { System.out.println( "Hello World!" ); }

…by choosing Run 'App.main()' from the context menu clicked in the code editor. That works, but the Maven install fails.

Executing clean and install in the Maven pane of IntelliJ does not solve the problem.

enter image description here

If I switch IntelliJ File > Project Structure > Project > Project SDK > from 10.0.1 to 1.8.0_171 (and set Project language level to 8 - Lambdas, type annotations etc.), then the Maven install succeeds.

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

If I return that setting to Java 10, the Maven install fails again, with same error.

I am running external Maven 3.5.3 rather than IntelliJ’s bundled older version, for no particular reason.

My older existing projects based on Java 8 have no problem. My only problem is trying to create new Maven-based quickstart projects using Java 10.

like image 591
Basil Bourque Avatar asked May 03 '18 21:05

Basil Bourque


1 Answers

Later version of maven-surefire-plugin

It seems the archetype is not yet updated for Java 10.

According to this blog post: http://joshlong.com/jl/blogPost/java-10.html, you can do the following to get it up and running...

.... I want to use Java 10, though, so I opened the pom.xml file and changed the java.version property value to be 10. The Maven surefire plugin broke the build next; it was complaining about not being able to parse the version of the JDK. I overrode the version by redefining the property for the plugin's version: 2.21.0.

The important part here is I think updating to the higher version of surefire, as mentioned in the comments. As of 2018-10, the current version is 2.22.1.

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
</plugin>
like image 95
Maarten Avatar answered Sep 28 '22 19:09

Maarten