1

我想使用 maven 来构建存在未解决编译问题的项目。

主要目的是使用包含编译错误的类的某种存根来打包和部署或运行​​应用程序,就像我理解 Eclipse 所做的那样(感谢JDT Core)。

我按照使用非 Javac 编译器中的Apache Maven 文档配置 maven java 编译器插件以使用 Eclipse 编译器。认为可能应该设置一些参数来修改编译器/构建器行为我正在阅读帮助 Eclipse - 编译 Java 代码,但我不知道哪个编译器/构建器选项或这些选项的组合可以解决问题。

到目前为止,maven java编译器插件的下一个配置使用eclipse编译器编译,并打包应用程序,包括为java类生成的.class(jvm字节码),没有编译错误。要获得这种行为,它只需要使用 eclipse 编译器(请参阅 compilerId 和依赖项)并设置failOnError=false.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <compilerId>eclipse</compilerId>
        <source>1.7</source>
        <target>1.7</target>
        <optimize>true</optimize>
        <showWarnings>true</showWarnings>
        <showDeprecation>true</showDeprecation>
        <failOnError>false</failOnError>
        <compilerArguments>
            <org.eclipse.jdt.core.compiler.problem.fatalOptionalError>disabled</org.eclipse.jdt.core.compiler.problem.fatalOptionalError>
            <org.eclipse.jdt.core.compiler.problem.forbiddenReference>ignore</org.eclipse.jdt.core.compiler.problem.forbiddenReference>
        </compilerArguments>
    </configuration>

    <dependencies>
         <dependency>
              <groupId>org.codehaus.plexus</groupId>
              <artifactId>plexus-compiler-eclipse</artifactId>
              <version>2.3</version>
         </dependency>
    </dependencies>
</plugin>

使用此配置,只要执行不使用未包含编译错误的类(因为未生成存根),我就可以运行 java 应用程序,但在 Java EE 容器上,类加载将失败,因此永远无法部署应用程序.

我很感激这方面的任何帮助。

4

1 回答 1

3

只是为了分享解决方案,那一刻我只是将其替换为plexus-compiler-eclipsetycho-compiler-jdt获得所需的行为。

proceedOnError参数表示它必须不顾错误地继续编译,转储带有问题方法或问题类型的类文件如何处理编译错误。

接下来是最终的配置示例。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <compilerId>jdt</compilerId>
        <source>1.7</source>
        <target>1.7</target>
        <optimize>true</optimize>
        <failOnError>false</failOnError>
        <compilerArguments>
            <proceedOnError/>
        </compilerArguments>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-compiler-jdt</artifactId>
            <version>0.22.0</version>
        </dependency>
    </dependencies>
</plugin>

Tycho FAQ中有更多插件配置示例。可能的编译器参数Java 开发用户指南(Eclipse 帮助站点)的使用批处理编译器部分中进行了描述。

于 2015-07-07T23:11:00.377 回答