【问题标题】:Enable javac warnings in maven build在 Maven 构建中启用 javac 警告
【发布时间】:2015-05-21 11:54:17
【问题描述】:

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

目前,当我使用 Eclipse 时,IDE 会为我突出显示警告。因此,当我使用 maven 构建项目时,我希望有这种行为。

提前致谢。娟

【问题讨论】:

    标签: maven javac compiler-warnings


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

    你只需要在你的 pom.xml 中添加 &lt;showWarnings&gt;true&lt;/showWarnings&gt; 到 maven 编译器插件。

    请查看 maven 编译器文档here

    【讨论】:

    • 这对我不起作用。我用一个单一的类和一个从未使用过的变量创建了一个新的 maven 项目,它应该抛出一个未使用的变量警告,但它没有
    猜你喜欢
    • 2017-08-20
    • 2013-11-20
    • 2018-08-26
    • 1970-01-01
    • 2017-04-14
    • 2017-10-28
    • 2013-03-03
    • 2020-10-15
    • 1970-01-01
    相关资源
    最近更新 更多