2013-03-12 3 views
5

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 

답변

7

이것은 당신의 소스와 "나를 위해 작동"mvn clean compile 실행

다음과 같은 출력을 얻을 수 있습니다.

<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.buck</groupId> 
    <artifactId>mavenproject3</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>mavenproject3</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

    <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> 
      <showWarnings>true</showWarnings> 
      <showDeprecation>true</showDeprecation> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

나는 이유는 당신은 "모든"태그는 의미로 떨어질 것이라고

   <compilerArguments> 
        <Xlint:all /> 
       </compilerArguments> 

때문에 XML 네임 스페이스 "Xlint"의 실패와 시도를 주석 상상 그 전체 태그 "Xlint : all"은 아마도 다른 네임 스페이스와 모두에있는 maven 구성 파서에서도 보지 못했을 것입니다. 그런데

, 관련
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" 

아마도 당신은 특정 플랫폼 버그 밟았?

+1

게시 한 방법을 사용하면 컴파일러 플러그인이 중첩 된 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 : 모든 \t \t \t \t \t"- 어쩌면 내가 사용하고있는 버전이 다른 의미를 가지고?maven-compiler-plugin version 3.0을 지정했습니다. –

+0

@RonDahlgren 죄송합니다. 초기 답변을 엉망으로 만들었습니다. 편집 된 내용이 유용 할 것입니다. –

+1

마치 내 javac처럼 보입니다! Openjdk가이 정적 메소드 사용법을 올바르게 포착하지 않은 것 같습니다. 게시 한 pom이 의도 한대로 작동하지만 javac은이를 무시하기 만합니다. 'javac -Xlint : all App.java'를 직접 사용하여 확인되었습니다. 도와 주셔서 감사합니다! –