Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-2093

--enable-preview is not recognized

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Bug
    • 3.0.0-M6
    • None
    • Maven Surefire Plugin
    • None

    Description

      pom:

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.my.example</groupId>
          <artifactId>Testing</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <properties>
              <maven-compiler-plugin-version>3.10.1</maven-compiler-plugin-version>
              <maven-surefire-plugin-version>3.0.0-M6</maven-surefire-plugin-version>
              <java-version>18</java-version>
              <junit-version>5.8.2</junit-version>
          </properties>
          <dependencyManagement>
              <dependencies>
                  <dependency>
                      <groupId>org.junit</groupId>
                      <artifactId>junit-bom</artifactId>
                      <version>${junit-version}</version>
                      <type>pom</type>
                      <scope>import</scope>
                  </dependency>
              </dependencies>
          </dependencyManagement>
          <dependencies>
              <dependency>
                  <groupId>org.junit.jupiter</groupId>
                  <artifactId>junit-jupiter</artifactId>
                  <scope>test</scope>
              </dependency>
          </dependencies>
          <build>
              <finalName>Testing</finalName>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>${maven-compiler-plugin-version}</version>
                      <configuration>
                          <release>${java-version}</release>
                          <compilerArgs>
                              <arg>--enable-preview</arg>
                              <arg>--add-modules=jdk.incubator.foreign</arg>
                          </compilerArgs>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-surefire-plugin</artifactId>
                      <version>${maven-surefire-plugin-version}</version>
                      <configuration>
                          <argLine>--enable-preview</argLine>
                          <argLine>--add-modules=jdk.incubator.foreign</argLine>
                          <argLine>--enable-native-access=ALL-UNNAMED</argLine>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
      </project> 

      Under src/test/java add this class:

      package com.my.example.simple;
      
      import org.junit.jupiter.api.Test;
      import jdk.incubator.foreign.ResourceScope;
      
      public class ExampleTest {
      
          @Test
          public void test1() {
              try (ResourceScope scope = ResourceScope.newConfinedScope()) {
              } catch (Throwable e) {
                  e.printStackTrace();
                  throw e;
              }
          }
      }

      Run Maven test.

      The project compiles fine. The tests fail with:

      Preview features are not enabled for com/my/example/simple/ExampleTest (class file version 62.65535). Try running with '--enable-preview'

      --enable-preview is already specified.

      Attachments

        Activity

          People

            olamy Olivier Lamy
            nlisker Nir Lisker
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: