Maven Toolchain config for jdk17 not pickedup by surefire plugin 3.0.0.M7

Viewed 22

Trying to use maven toolchains to compile a Java 17 project while my active jdk is JDK8. I set up my toolchains so they use JDK17 to compile it, and this compilation fails while running tests with error:

Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M7:test failed: java.lang.UnsupportedClassVersionError: my/source/ControllerTest has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0.

My pom tooLchain config fr compiler and surefire plugin(version M7):

    <properties>
           .....
           <toolchain>17</toolchain>
            <vendor>oracle</vendor>
        </properties>
  ....
....

<plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-toolchains-plugin</artifactId>
                        <configuration>
                            <jdkToolchain>
                                <version>${toolchain}</version>
                                <vendor>${vendor}</vendor>
                            </jdkToolchain>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                         <configuration>
                        <jdkToolchain>
                                <version>${toolchain}</version>
                                <vendor>${vendor}</vendor>
                        </jdkToolchain>
                    </configuration>                       
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>                         
                            <jdkToolchain>
                                <version>${toolchain}</version>
                                <vendor>${vendor}</vendor>
                            </jdkToolchain>                    
                            <argLine>@{surefireArgLine}</argLine>
                            <forkCount>1</forkCount>
                            <reuseForks>false</reuseForks>
                            <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>                       
                            
                            <includes>
                                <include>**/**Test.java</include>
                            </includes>
                           
                        </config>

why isn't my toolchain config getting picked up by surefire. Compilation itself is fine, but surefire test phase fails. Appreciate your help

0 Answers
Related