Maven编译器插件空指针

时间:2018-04-20 10:20:19

标签: maven terminal

我在终端测试期间遇到问题。我需要运行mvn install,但是我得到了:

  public markContent(): void {
    const selection: any = window.getSelection();
    const range: any = selection.getRangeAt(0);

    if (range.startOffset !== range.endOffset) {
      if (this.markerEvent === 'p' || this.markerEvent === 'mark' || this.markerEvent === 'strong') {

        const textSeleted: string = selection.toString();
        const htmlSelection = this.getHtmlSelection(selection);

        const highlight: any = range.commonAncestorContainer;
        const blockContent: string = range.commonAncestorContainer.innerText;

        const start = blockContent.indexOf(textSeleted);
        const end = start + textSeleted.length;


        if (this.markerEvent !== 'mark') {
          const marker: any = {
            documentId: this.document.id,
            blockId: highlight.attributes['data-block-id'].value,
            start: start,
            end: end,
            color: this.colorMarker
          };
          const markerElement: any = document.createElement('mark');
          markerElement.setAttribute('class', this.colorMarker);
          markerElement.innerHTML = htmlSelection;
          range.deleteContents();
          range.insertNode(markerElement);
          this.hideBubble();
          console.log(marker);
          this.libraryServices.saveMarker(this.document.id, marker);
          return;
        }
        const p = document.createElement('p');
        p.style.display = 'inline';
        p.style.margin = '0';
        p.innerHTML = highlight.innerHTML;
        highlight.remove();
        range.deleteContents();
        range.insertNode(p);
        this.hideBubble();
      }
    }

  }

我尝试使用不同版本的编译器运行它。在Eclipse中运行testNG测试时,一切正常。通过终端运行时会出现此问题。这些是移动应用的黄瓜测试。 Runner使用Appium。

2 个答案:

答案 0 :(得分:1)

在JDK 11下运行maven 3.3.9编译时,我也得到Fatal error compiling: CompilerException: NullPointerException。 我切换到JDK 8,不再获得NullPointerException

答案 1 :(得分:0)

当maven编译器插件找不到源代码的某些必需部分时,就会发生这种情况。

让我告诉你我的情况:

  1. 我创建了一个Spring Boot应用程序并想对其进行测试
  2. 所以我创建了另一个maven模块来创建用于自动化GUI测试的API
  3. 覆盖了jar的创建方式,因此.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>

我在搜索bug in JDK classes时发现的另一个建议是在编译器插件上添加配置选项forceJavacCompilerUse

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