Surefire および Failsafe でプレビュー機能を有効にしてテストを実行すると問題が発生します 質問する

Surefire および Failsafe でプレビュー機能を有効にしてテストを実行すると問題が発生します 質問する

プロジェクトを Java 12 に移行しようとしています--enable-preview

--enable-previewコンパイラ設定に以下を追加しました:

        <plugin>                                                            
            <artifactId>maven-compiler-plugin</artifactId>                  
            <version>3.8.0</version>                                        
            <configuration>                                                 
                <release>12</release>                          
                <compilerArgs>                                                                                  
                    <arg>--enable-preview</arg>                             
                </compilerArgs>                                                                      
            </configuration>                                                
        </plugin>                                                                                                                                         

また、確実性とフェイルセーフ性のために argLine にも追加しました:

<properties>                                                                                             
    <argLine>--enable-preview</argLine>                        
</properties> 

そして、次のmvn clean verify結果を実行します。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project lombok-jdk10: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test failed: java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/kirela/lombok/BarTest (class file version 56.65535). Try running with '--enable-preview' -> [Help 1]

また、surefire/failsafe 構成に argLine を直接追加してみましたが、結果は同じでした。

ここで何が欠けているのでしょうか?

これはsurefire/failsafeのバグでしょうか?

編集2: Surefire と Failsafe 構成:

        <plugin>                                                            
            <groupId>org.apache.maven.plugins</groupId>                     
            <artifactId>maven-surefire-plugin</artifactId>                  
            <version>3.0.0-M3</version>                                     
            <configuration>                                                 
                <forkCount>2</forkCount>                                    
            </configuration>                                                
        </plugin>                                                           
        <plugin>                                                            
            <groupId>org.apache.maven.plugins</groupId>                     
            <artifactId>maven-failsafe-plugin</artifactId>                  
            <version>3.0.0-M3</version>                                     
            <executions>                                                    
                <execution>                                                 
                    <goals>                                                 
                        <goal>integration-test</goal>                       
                        <goal>verify</goal>                                 
                    </goals>                                                
                </execution>                                                
            </executions>                                                   
            <configuration>                                                 
                <forkCount>2</forkCount>                                    
            </configuration>                                                                                                                              
        </plugin> 

編集3: 最小限の動作例はここにあります:https://github.com/krzyk/lombok-jdk10-example

プロジェクトは で失敗します--enable-previewが、削除すると動作します。

ベストアンサー1

これは私にとってはうまくいきます:

  • mvn clean install動作する(JUnitテスト付き)
  • IDEAはモジュール言語レベルを正しく認識します。12 (Preview) - Switch expressions
  • IDEA 作業における junit テスト
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <release>12</release>
            <compilerArgs>
                <arg>--enable-preview</arg>
            </compilerArgs>
        </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>

環境:

  • Ubuntu 18.04.3 x64

  • アイデア 2019.2.1

  • メイヴン3.6.0

  • jdk:

     IMPLEMENTOR="Oracle Corporation"
     JAVA_VERSION="12"
     JAVA_VERSION_DATE="2019-03-19"
    

追加: 同様に、このアプローチは Java 13 でも機能します。

追加: 同様に、このアプローチは Java 17 でも機能します。

おすすめ記事