【问题标题】:How to compile Maven project with Xlint如何使用 Xlint 编译 Maven 项目
【发布时间】:2013-09-06 09:04:49
【问题描述】:

有没有办法通过命令行将编译器参数传递给 Maven?我知道我可以在 compiler-plugin 中指定它,但我也想从命令行运行 Xlint。所以我尝试了类似

mvn clean install -DskipTests=true -DcompilerArgument=-Xlint:deprecation

但没有成功。

【问题讨论】:

    标签: java maven compilation


    【解决方案1】:

    对于这个具体案例(弃用警告),实际上一个property which can be used from the command line

    mvn clean install -Dmaven.compiler.showDeprecation=true
    

    与 compilerArgument 解决方案相反,这也适用于在 maven 进程中使用编译器,而不仅仅是在使用 fork=true 时。

    一个类似有用的属性是maven.compiler.showWarnings

    【讨论】:

    • 谢谢,看起来真不错
    • 对于懒惰的人:-Dmaven.compiler.showDeprecation(没有=true)也可以:)
    【解决方案2】:

    你可以像这样定义一个编译器插件:

    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <compilerArgument>${compilerArgument}</compilerArgument>
        </configuration>
    </plugin>
    

    然后从命令行传递参数:

    mvn -DcompilerArgument=-Xlint:deprecation compile
    

    如果你不传递-DcompilerArgument,它不会破坏构建,因为编译器插件参数中的'compilerArgument'将为空并被忽略。

    【讨论】:

    • 不错,但我希望会有一些默认参数,这样我就可以保持我的 pom.xml 完好无损。但是很好的解决方法,谢谢
    • 不幸的是,附加参数的compile:compile parameters 都没有默认用户属性。
    猜你喜欢
    • 2016-10-01
    • 2015-06-02
    • 1970-01-01
    • 2014-05-17
    • 2021-06-25
    • 2016-10-27
    • 1970-01-01
    • 2019-02-28
    • 2021-11-05
    相关资源
    最近更新 更多