0

我正在尝试使用检查器框架在项目中编译 groovy (+spock) 文件。它失败了,我需要一些提示如何找到解决方案..

错误是

Compilation failure
Failure executing groovy-eclipse compiler:
----------
1. ERROR in /tmp/test/my-app/src/main/java/com/mycompany/app/App.java (at line 0)
    package com.mycompany.app;
    ^
Internal compiler error: java.lang.IllegalArgumentException at com.sun.source.util.JavacTask.instance(JavacTask.java:66)
----------
1 problem (1 error)


Caused by: org.apache.maven.plugin.compiler.CompilationFailureException:     at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1215)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:188)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)

我创建了一个示例项目:

$ mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

然后我将 POM 修改为如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>my-app</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>

    <!-- checker framework -->
    <org.checkerframework.version>2.1.14</org.checkerframework.version>
    <checker.version>${org.checkerframework.version}</checker.version>

    <!-- spock and groovy -->
    <groovy-all.version>2.4.15</groovy-all.version>
    <groovy-eclipse-batch.version>2.4.3-01</groovy-eclipse-batch.version>
    <groovy-eclipse-compiler.version>2.9.2-04</groovy-eclipse-compiler.version>
    <spock-core.version>1.2-groovy-2.4</spock-core.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.checkerframework</groupId>
        <artifactId>checker</artifactId>
        <version>${checker.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!-- only for IDE and compile -->
    <dependency>
      <groupId>org.checkerframework</groupId>
      <artifactId>checker</artifactId>
      <scope>provided</scope>
    </dependency>
    <!-- for tests -->
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>${groovy-all.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.spockframework</groupId>
      <artifactId>spock-core</artifactId>
      <version>${spock-core.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <!-- This profile will be active only if the executing JVM is a Java 7 JVM. -->
      <!-- It enhance the checker framework with an annotated JVM Version and a javac supports these annotations. -->
      <id>checkerframework-jdk7</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <jdk>1.7</jdk>
      </activation>

      <properties>
        <compiler.version>${org.checkerframework.version}</compiler.version>
        <jdk7.version>${org.checkerframework.version}</jdk7.version>
      </properties>

      <!-- These checker framework dependencies are only required to fill the properties via maven-dependencies-plugin. -->
      <!-- These properties are required to resolve the JAR locations and use as compiler arguments. -->
      <dependencies>
        <!-- The type annotations compiler - needed for Java 7 -->
        <dependency>
          <groupId>org.checkerframework</groupId>
          <artifactId>compiler</artifactId>
          <version>${compiler.version}</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.checkerframework</groupId>
          <artifactId>jdk7</artifactId>
          <version>${jdk7.version}</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <inherited>true</inherited>
            <executions>
              <execution>
                <id>default-compile</id>
                <configuration>
                  <compilerArgs>
                    <arg>-J-Xbootclasspath/p:${org.checkerframework:compiler:jar}</arg>
                    <arg>-Xbootclasspath/p:${org.checkerframework:jdk7:jar}</arg>
                  </compilerArgs>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <!-- This profile will be active only if the executing JVM is a Java 7 JVM. -->
      <!-- It enhance the checker framework with an annotated JVM Version and a javac supports these annotations. -->
      <id>checkerframework-jdk8</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <jdk>1.8</jdk>
      </activation>

      <properties>
        <jdk8.version>${org.checkerframework.version}</jdk8.version>
      </properties>

      <!-- These checker framework dependencies are only required to fill the properties via maven-dependencies-plugin. -->
      <!-- These properties are required to resolve the JAR locations and use as compiler arguments. -->
      <dependencies>
        <dependency>
          <groupId>org.checkerframework</groupId>
          <artifactId>jdk8</artifactId>
          <version>${jdk8.version}</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <inherited>true</inherited>
            <executions>
              <execution>
                <id>default-compile</id>
                <configuration>
                  <compilerArgs>
                    <arg>-Xbootclasspath/p:${org.checkerframework:jdk8:jar}</arg>
                  </compilerArgs>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>checkerframework</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>properties</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <inherited>true</inherited>
            <executions>
              <execution>
                <id>default-compile</id>
                <configuration>
                  <fork>true</fork>
                  <annotationProcessorPaths>
                    <path>
                      <groupId>org.checkerframework</groupId>
                      <artifactId>checker</artifactId>
                      <version>${checker.version}</version>
                    </path>
                  </annotationProcessorPaths>
                  <annotationProcessors>
                    <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                  </annotationProcessors>
                  <useIncrementalCompilation>false</useIncrementalCompilation>
                  <!-- Use the deprecated configuration 'compilerArguments' to make it possible to enhance the -->
                  <!-- configuration in jdk7 profile without overwriting these settings. -->
                  <compilerArguments>
                    <AprintErrorStack />
                    <AprintAllQualifiers />
                    <AprintVerboseGenerics />
                    <Adetailedmsgtext />
                  </compilerArguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerId>groovy-eclipse-compiler</compilerId>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>${groovy-eclipse-compiler.version}</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>${groovy-eclipse-batch.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>

请注意,此项目必须具备 Java 7 兼容性,不使用 Java 8 配置文件。checkerframework 仅在 CI 中测试时被激活,这也是编译失败的命令:

$ mvn clean verify -Pcheckerframework

任何提示/帮助表示赞赏!groovy-eclipse-compiler版本从这里2.9.2-04加载

4

0 回答 0