lint 수준 경고를 출력하도록 maven을 설정하려고합니다. 비 정적 컨텍스트에서 정적 메서드를 사용하는 것에 대한 경고를 생성해야하는 작은 테스트 프로그램을 만들었지 만 여러 가지 다른 플러그인 구성 옵션에도 불구하고 빌드는 항상 경고없이 성공합니다!-Xlint : all 및 maven에 문제가 발생했습니다.
Google 검색 중 일부를 수행 한 후 컴파일러 플러그인의 'compilerArgument (s)'속성을 사용하라는 제안을 발견했지만이 문제는 저에게 맞지 않습니다. 자바 6 문자열에 대한 javadoc로,
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"));
}
}
이 프로그램은 경고를 발행한다 :: 형식은이 방법의 정적 버전이 존재한다는 것을 나타냅니다
는 여기에서 경고를 생성해야 내 샘플 프로그램입니다. 나는 두 형태를 시도했습니다
<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>
: 그것은 과거에 나를 물린하고 컴파일러가 여기에
내 POM 파일입니다 :-)를 감지합니다으로 나는 특히이 사건을 잡으려면 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가이 정적 메소드 사용법을 올바르게 포착하지 않은 것 같습니다. 게시 한 pom이 의도 한대로 작동하지만 javac은이를 무시하기 만합니다. 'javac -Xlint : all App.java'를 직접 사용하여 확인되었습니다. 도와 주셔서 감사합니다! –