我正在尝试让 Maven 输出棉绒级别警告。我创建了一个小型测试程序,它应该生成一个关于在非静态上下文中使用静态方法的警告,但是尽管有许多不同的插件配置选项,构建总是成功而没有任何警告!
在进行了一些谷歌搜索之后,我发现了使用编译器插件的“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文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dahlgren</groupId>
<artifactId>JavaScratchSpace</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>JavaScratchSpace</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<!--
<compilerArguments>
<Xlint:all />
</compilerArguments>
-->
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.dahlgren.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我尝试了两种形式的 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