2012-09-16 23 views
37

在NetBeans 7.2中,我無法找到如何使用-Xlint進行編譯:未選中Maven項目。在Ant項目下,您可以通過轉到項目屬性 - >編譯來更改編譯器標誌,但Maven項目似乎沒有任何此類選項。如何使用-Xlint進行編譯:在Maven項目中未選中?

是否有任何方法來配置IDE使用Maven這樣的標誌進行編譯?

+0

如果您需要傳遞多個參數,你可能會收到一個錯誤'< compilerArgument>'。看到這個答案的替代' ... ':https://stackoverflow.com/a/23743186/257299 – kevinarpe

回答

57

我想你可以在你的pom.xml中設置編譯器參數。請參考http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html

<compilerArgument>-Xlint:unchecked</compilerArgument> 
+0

我已經創建了一個小的測試程序,應該會產生一個關於靜態方法,但我似乎無法讓maven生成任何警告。要點示例程序和pom文件張貼在這裏 - > https://gist.github.com/influenza/5145598 –

+0

@RonDahlgren:你爲什麼會期望這會發出警告? – haylem

+0

@haylem - 訪問一個靜態字段或方法應該會生成一個警告。這是所使用的javac的細節,但它很常見:http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcompiler %2Fref-preferences-errors-warnings.htm和http://pic.dhe.ibm.com/infocenter/dstudio/v3r1/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences% 2Fjava%2Fcompiler%2Fref-preferences-errors-warnings.htm –

21

我想詳細說明@ Nishant的答案。 compilerArgument標籤需要進入plugin/configuration標籤。這裏是一個完整的例子:

<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.3</version> 
    <configuration> 
     <source>1.8</source> 
     <target>1.8</target> 
     <testSource>1.8</testSource> 
     <testTarget>1.8</testTarget> 
     <compilerArgument>-Xlint:unchecked</compilerArgument> 
    </configuration> 
    </plugin> 
</plugins> 
0

pom文件信息是現貨。我還有另一項挑戰,即在Jenkins中構建別人的Maven項目,並且無法訪問pom文件存儲庫。

我創建了一個預生成步驟從混帳下載後插入編譯器參數到POM文件,例如

sed -i 's|/target> *$|/target>\n<compilerArgument>\n-Xlint:deprecation\n</compilerArgument>|' $WORKSPACE/pom.xml 
相關問題