【发布时间】:2015-05-21 11:54:17
【问题描述】:
我想在使用 maven 从命令行构建项目时看到 java 代码警告。
目前,当我使用 Eclipse 时,IDE 会为我突出显示警告。因此,当我使用 maven 构建项目时,我希望有这种行为。
提前致谢。娟
【问题讨论】:
标签: maven javac compiler-warnings
我想在使用 maven 从命令行构建项目时看到 java 代码警告。
目前,当我使用 Eclipse 时,IDE 会为我突出显示警告。因此,当我使用 maven 构建项目时,我希望有这种行为。
提前致谢。娟
【问题讨论】:
标签: maven javac compiler-warnings
使用 javac 编译器无法实现类似 IDE 的警告级别,因此您必须使用非 javac 编译器。下面是一个POM sn-p:
<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>
<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>
【讨论】:
你只需要在你的 pom.xml 中添加 <showWarnings>true</showWarnings> 到 maven 编译器插件。
请查看 maven 编译器文档here。
【讨论】: