Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create spring boot maven project with java 12?

I am trying to create web app using spring boot, maven and java 12. I started the project with spring-boot-starter-parent version 2.1.5.RELEASE, java 12 and maven-compiler-plugin version 3.8.1. I tried to run ./mvnw package but i got this error:

Fatal error compiling: invalid target release: 12

After that i wrote on the internet that maven compiler plugin uses old dependency for asm and i should specify new version of it. So i selected the latest version of asm which is 7.1 and i added configuration tag with properties release 12 and compilerArgs --enable-preview for java 12. The result was:

Fatal error compiling: invalid flag: --release

The next thing that i tried was to use spring boot starter parent version 2.2.0.M3 and to specify the repository to find milestone versions of spring from http://repo.spring.io/milestone. Unfortunately i got the same result. Any ideas?

like image 989
Angel Avatar asked Jun 07 '19 10:06

Angel


People also ask

What is the minimum java version need for Spring Boot?

System Requirements Spring Boot 2.7. 5 requires Java 8 and is compatible up to and including Java 19. Spring Framework 5.3. 23 or above is also required.

Which version of java does Maven use?

Maven Configuration The Maven tool uses JDK version 11.0. 10. The default JDK is set to 13.0.

Does Maven work with java 17?

In case of Maven, we specify the compiler plugin to use Maven with Java 17. The next step is to basically upgrade the dependencies of our application.

Can we create Spring Boot application using Maven?

Make sure you choose Maven as Type. In the next screen, you can choose the dependencies that you want to add to your Spring Boot project. Once you click Finish, Maven will take some time to download all the dependencies and initialize the project. Now your Spring project is ready!


1 Answers

Trying with previous versions to spring boot 2.2.0.MX it also failed for me, but I have managed to make it work with 2.2.0.M6 including some plugins and tweaking them to adapt with the preview features like:

       <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <arguments>--enable-preview</arguments>
                    <jvmArguments>--enable-preview</jvmArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <argLine>--enable-preview</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <compilerArgs>--enable-preview</compilerArgs>
                </configuration>
            </plugin>
       </plugins>    

This is now working with Java 13.

like image 194
Francisco Miguel Cejudo Avatar answered Sep 23 '22 01:09

Francisco Miguel Cejudo