-Xlint麻烦:全部和maven

我正在尝试让maven输出lint级警告。 我已经创建了一个小的测试程序,它应该生成一个关于从非静态上下文中使用静态方法的警告,但是尽管有许多不同的插件配置选项,但构建总是成功而没有任何警告!

在做了一些谷歌搜索后,我发现了使用编译器插件的’compilerArgument(s)’属性的建议,但这对我来说似乎也没有用。

这是我应该生成警告的示例程序:

package com.dahlgren; /** * Test space * */ public class App { public static void main( String[] args ) { String foo = "foo"; // I want this to generate a compilation warning System.out.println(foo.format("blah")); } } 

此程序应发出警告,因为Java 6 String :: format的javadoc表示仅存在此方法的静态版本。 我想特别抓住这个案例,因为它过去曾经咬过我,编译器应该检测它:-)

这是我的pom文件:

  4.0.0 com.dahlgren JavaScratchSpace 1.0-SNAPSHOT jar JavaScratchSpace http://maven.apache.org  UTF-8     org.apache.maven.plugins maven-compiler-plugin 3.0  1.6 1.6 -Xlint:all <!--    --> true true    maven-assembly-plugin   jar-with-dependencies    com.dahlgren.App      package  single        

我已经尝试过两种forms的compilerArgument(s)属性都无济于事。

运行mvn clean compile产生以下输出:

 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building JavaScratchSpace 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.3:clean (default-clean) @ JavaScratchSpace --- [INFO] Deleting file set: /work/fun/JavaScratchSpace/target (included: [**], excluded: []) [INFO] [INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ JavaScratchSpace --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /work/fun/JavaScratchSpace/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ JavaScratchSpace --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /work/fun/JavaScratchSpace/target/classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.716s [INFO] Finished at: Tue Mar 12 11:39:21 PDT 2013 [INFO] Final Memory: 8M/150M [INFO] ------------------------------------------------------------------------ 

其他版本信息:

 $ mvn --version && javac -version Apache Maven 3.0.4 Maven home: /usr/share/maven Java version: 1.6.0_24, vendor: Sun Microsystems Inc. Java home: /usr/lib/jvm/java-6-openjdk-amd64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "3.2.0-29-generic", arch: "amd64", family: "unix" javac 1.6.0_24 

这对你来说很“适合我”。

  4.0.0 com.buck mavenproject3 1.0-SNAPSHOT jar mavenproject3 http://maven.apache.org  UTF-8    junit junit 3.8.1 test      org.apache.maven.plugins maven-compiler-plugin 3.0  1.6 1.6 -Xlint:all true true      

我想象你注释出来的原因

     

由于XML命名空间“Xlint”会导致“all”标记落入,这意味着maven配置解析器甚至可能看不到整个标记“Xlint:all”(位于不同的命名空间中) )。

顺便说一句,相关的产出线

 Compiling 1 source file to C:\Users\edwbuck\Documents\NetBeansProjects\mavenproject3\target\classes bootstrap class path not set in conjunction with -source 1.6 com/buck/mavenproject3/App.java:[12,35] static method should be qualified by type name, java.lang.String, instead of by an expression 

和我的环境

 Apache Maven 3.0.4 (r1232337; 2012-01-17 02:44:56-0600) Maven home: C:\Program Files\NetBeans 7.2.1\java\maven Java version: 1.7.0_07, vendor: Oracle Corporation Java home: C:\Program Files (x86)\Java\jdk1.7.0_07\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 7", version: "6.1", arch: "x86", family: "windows" 

也许你踩到了特定于平台的bug?