显示编译器警告而不编辑pom.xml

she*_*lic 6 compiler-warnings maven

我想在使用Maven编译时始终显示编译器警告和弃用.我知道如何通过编辑来实现pom.xml,但我希望这种行为默认只为我自己(所以我无法编辑pom.xml).

我试过了:

mvn -Dmaven.compiler.showWarnings=true -Dmaven.compiler.showDeprecation=true clean compile
Run Code Online (Sandbox Code Playgroud)

但这并没有显示任何警告(如果我修改pom.xml它们以显示它们,它们就在那里).

两个表达式(maven.compiler.showWarningsmaven.compiler.showDeprecation)都存在.

我错过了什么?

Wou*_*ens 0

您也许可以将它们包装在 Maven 配置文件中,然后使用 -P 指定配置文件。

它会是这样的(不过我没有测试过):

<profiles>
    <profile>
        <id>development</id>
        <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <!-- compiler options go here -->
            </configuration>
        </plugin>
        </build>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

然后运行为

mvn compile -Pdebug
Run Code Online (Sandbox Code Playgroud)