簡體   English   中英

Maven 編譯器插件 null 指針

[英]Maven compiler plugin null pointer

我在終端運行測試時遇到問題。 我需要運行 mvn install,但我得到:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project ProjectName: Fatal error compiling: CompilerException: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project ProjectName: Fatal error compiling
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)

我嘗試使用不同版本的編譯器運行它。 當 testNG 在 Eclipse 中運行測試時,一切正常。 通過終端運行時會出現問題。 這些是移動應用程序的 cucumber 測試。 Runner 使用 Appium。

在 JDK 11 下運行 maven 3.3.9 編譯時,我也遇到了Fatal error compiling: CompilerException: NullPointerException 。我切換到 JDK 8 並且不再得到NullPointerException

當 maven 編譯器插件找不到源代碼的某些必需部分時,就會發生這種情況。

說一下我的情況:

  1. 我創建了一個 spring boot 應用程序並想測試它
  2. 所以我創建了另一個 maven 模塊來創建用於自動化 GUI 測試的 API
  3. 覆蓋了 jars 的創建方式,因此 .jar 中的目錄發生了變化,所以我不得不調整來為我生成 jar
  4. 我忘了在這個插件中包含一個包(服務)所以你出現了同樣的錯誤

所以......我包含了這個包並且它起作用了

     <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>inventarios.Inventarios</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <!--to be imported on other projects-->
                        <classifier>app-to-import</classifier>
                        <includes>
                            <include>**/desktop/*</include>
                            <include>**/desktop/navigation/*</include>
                            <include>**/service/*</include> <!--the package I forgot-->
                            <include>**/util/*</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我在搜索JDK 類中錯誤時發現的另一個建議是在編譯器插件上添加配置選項forceJavacCompilerUse

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <version>3.8.1</version>
   <configuration>
      <forceJavacCompilerUse>true</forceJavacCompilerUse>
   </configuration>
</plugin>

Maven 編譯器插件中有一個未解決的問題, https://issues.apache.org/jira/browse/MCOMPILER-346

根本問題通常是由被掩蓋的編譯器錯誤引起的。 要找出編譯器錯誤, -Dmaven.compiler.forceJavacCompilerUse=true傳遞給mvn命令行。 修復編譯器錯誤后,問題就消失了。

我遇到了同樣的問題,這是因為 java 版本我通過https://sdkman.io/更改了它們

查看更多https://www.wimdeblauwe.com/blog/2018/2018-09-26-switching-between-jdk-8-and-11-using-sdkman-/

我希望它可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM