簡體   English   中英

Maven編譯器插件構建失敗,帶有Werror參數,並顯示標記為跳過的警告

[英]Maven Compiler Plugin Build Failure with Werror argument and present warnings marked to be skipped

我正在嘗試使用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條警告-棄用,未經檢查,原始類型。 如果刪除這些參數,則構建會失敗,這是完全可以的。 --

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

但是,當我添加這些參數時,編譯器應忽略此類警告,並且構建應成功。 但是Build仍然失敗,並且沒有顯示任何特定的錯誤。 如果刪除此參數,則構建成功。

 <arg>Werror</arg>

因此,如果我們跳過項目中存在的某些警告,則無法運行成功的構建。 有什么辦法可以達到相同目的?

PFB mvn build命令的錯誤輸出-

    [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

經過大量的更改之后,如果所有的Lint警告均已修復,我最終可以使用“ Werror”標志找出如何成功構建的方法。

我刪除了-“ true”無法確切說明使用Javac編譯器時構建失敗的原因是什么。

以及添加的UTF-8編碼和禁止的處理棉絨警告。

配置的工作副本是-

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
        <encoding>UTF-8</encoding>
                <source>1.8</source>
                <target>1.8</target>
                <showWarnings>true</showWarnings>
                <compilerArgs>
         <arg>-Xlint:all</arg>
         <arg>-Xlint:-processing</arg>
                </compilerArgs>
            </configuration>
        </plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM