2017-10-06 198 views
0

我想使用Maven编译器插件来显示所有的警告,并通过配置“Werror”参数,如果有任何警告的构建失败。我对Maven插件编译pom.xml文件中设置的是 -Maven编译器插件编译失败与Werror参数和目前的警告被标记为跳过

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

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

<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 
+0

与此错误失败 - [错误]未能执行目标org.apache.maven.plugins:Maven的编译器插件: 3.5.1:关于项目的编译(默认编译)vsmvam:编译失败 - > [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException:未能执行目标org.apache.maven.plugins:maven-compiler-plugin :3.5.1:编译(默认编译)项目vsmvam:Compila (MojoExecutor.java:213) –

+0

请发布完整的错误和日志输出... – khmarbaise

+0

添加了mvn build命令的错误输出。 –

回答

0

做改变我能够最终弄清楚如何与“Werror”标志成功打造,如果所有的lint警告是固定的,之后很多。

我删除了 - “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>