lintレベルの警告を出力するようにmavenを取得しようとしています。静的でないコンテキストから静的メソッドを使用することに関する警告を生成する小さなテストプログラムを作成しましたが、多くの異なるプラグイン設定オプションにもかかわらず、ビルドは常に警告なしで成功します。-Xlintで問題:allと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ためjavadocとして、警告を発行する必要があります::フォーマットは、この方法の唯一の静的なバージョンが存在することを示しています。私は両方の形式を試してみた
<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)の属性を使用できません。
[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
投稿したメソッドを使用すると、コンパイラプラグインはネストされたxmlタグを実際のコンパイラパラメータとして解釈するようです。 Mavenは以下を出力します: "目標org.apache.maven.pluginsを実行できませんでした:maven-compiler-plugin:3.0:プロジェクトのコンパイル(デフォルトコンパイル)JavaScratchSpace:致命的なコンパイル:無効なフラグ:-compilerArgument" "\t \t \t \t \t \t \t \t \t \t \t -Xlint:すべての compilerArgument> \t \t \t \t \t compilerArguments>" を使用して - 多分私が使用していたバージョンは異なる意味を持っていますか?私はmaven-compiler-plugin version 3.0を指定しました –
@RonDahlgren申し訳ありません、私は最初の答えを本当に乱してしまったことに気付きました。うまくいけば、編集されたものがあなたに役立つでしょう。 –
それは私のjavacだったようですね! openjdkがこの静的メソッドの使用法を正しくキャッチしていないように見えます。投稿したポームは意図したとおりに動作しますが、javacはそれを無視するだけです。 'javac -Xlint:all App.java'を使って直接検証します。助けてくれてありがとう! –