【发布时间】:2014-07-28 02:59:45
【问题描述】:
我想使用 maven 构建存在未解决编译问题的项目。
主要目的是使用包含编译错误的类的某种存根来打包和部署或运行应用程序,就像我理解的 Eclipse 所做的那样(感谢JDT Core)。
我按照Using Non-Javac compiler 的 Apache Maven 文档配置 maven java 编译器插件以使用 Eclipse 编译器。认为可能应该设置一些参数来修改我正在阅读的编译器/构建器行为 Help Eclipse - Compiling Java code 但我不知道哪个编译器/构建器选项或这些选项的组合可以解决问题。
到目前为止,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 容器上,类加载将失败,因此应用程序可以永远不会被部署。
感谢您对此提供的任何帮助。
【问题讨论】:
-
请更新错误日志!
-
@eliasah 设置
failOnErrorfalse,编译阶段将所有编译错误显示为警告,并完成所有项目的成功消息打包。设置为 true 只显示编译错误,如导入问题,但不显示项目结构或项目之间的依赖关系。
标签: java maven eclipse-jdt maven-compiler-plugin