在 Maven 构建中启用 javac 警告

Enable javac warnings in maven build

我想在使用 maven 从命令行构建项目时看到 java 代码警告。

目前,当我使用 eclipse 时,IDE 会为我突出显示警告。所以我希望在使用 Maven 构建项目时具有这种行为。

提前致谢。娟

你只需要在你的pom.xml中添加<showWarnings>true</showWarnings>到maven编译插件。

请查看 maven 编译器文档 here

使用 javac 编译器无法达到

IDE 级别的警告,因此您必须使用非 javac 编译器。下面是一个 POM 片段:

<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>