Maven编译器插件构建失败,带有Werror参数和标记为跳过的当前警告

时间:2017-10-06 07:11:24

标签: java maven maven-compiler-plugin

我正在尝试使用Maven编译器插件来显示所有警告,如果有任何警告,则通过配置“Werror”参数使构建失败。我的maven编译器插件的Pom.xml文件设置是 -

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <forceJavacCompilerUse>true</forceJavacCompilerUse>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArgs>
        <arg>-Xlint:all</arg>
        <arg>-Xlint:-deprecation</arg>
        <arg>-Xlint:-unchecked</arg>
        <arg>-Xlint:-rawtypes</arg>
        <arg>-g</arg>
        <arg>Werror</arg>
                </compilerArgs>
                <verbose>true</verbose>
                <showWarnings>true</showWarnings>
            </configuration>
        </plugin>

在我的项目中,我有3个警告 - 弃用,未选中,rawtypes。 如果我删除这些参数,那么构建失败,这是完全正常的。 -

    <arg>-Xlint:-deprecation</arg>
    <arg>-Xlint:-unchecked</arg>
    <arg>-Xlint:-rawtypes</arg>

但是当我添加这些参数时,编译器应该忽略这些警告并且构建应该成功。 但是Build仍然失败并且没有显示任何特定错误。 如果删除此参数,构建成功。

 <arg>Werror</arg>

所以我无法运行成功的构建如果我们跳过项目中存在的一些警告。有没有办法实现同样的目标?

PFB mvn构建命令的错误输出 -

    [INFO] Error stacktraces are turned on.
     [INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.abcd:project:war:1.0
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.abcd.xyz:common:jar -> duplicate declaration of version 1.3 @ line 87, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building PROJECT 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ vsmvam ---
[INFO] Deleting /home/ess/p4-sources/abcd/xyz/project/target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.6.1.201212231917:prepare-agent (default) @ vsmvam ---
[INFO] argLine set to -javaagent:/home/ess/.m2/repository/org/jacoco/org.jacoco.agent/0.6.1.201212231917/org.jacoco.agent-0.6.1.201212231917-runtime.jar=destfile=/home/ess/p4-sources/mgmtplatform/vshield-main/vsmvam/target/jacoco.exec,excludes=com/vmware/vshield/vsm/**
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ vsmvam ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 13 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ vsmvam ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 330 source files to /home/ess/p4-sources/abcd/xyz/project/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.590s
[INFO] Finished at: Fri Oct 06 01:51:08 PDT 2017
[INFO] Final Memory: 39M/892M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project vsmvam: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project vsmvam: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:976)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

1 个答案:

答案 0 :(得分:0)

在做了很多改变之后,我终于弄明白了如何用&#34; Werror&#34;如果所有Lint警告都已修复,则标记。

我删除了 - &#34; true&#34; 无法弄清楚当我们使用Javac编译器时构建失败的原因。

添加了UTF-8编码并抑制了Processing Lint警告。

配置的工作副本是 -

public class MyObject {
    public string MyProperty { get; set; }
}