2015-08-28 65 views
6

當我運行一個PMD分析我recive衝突:抑制違法行爲PMD

Each class should declare at least one constructor 

這是違背一個Spring控制器上。這個控制器是由Spring實例化的,因此不應該調用這個類。

什麼是忽略這種違規行爲的推薦方式?

根據http://pmd.sourceforge.net/pmd-4.3/suppressing.html可以使用// NOPMD,但我只是想忽略特定的違規行爲。

回答

4

PMD還支持@SuppressWarnings註釋:

// This will suppress all the PMD warnings in this class 
@SuppressWarnings("PMD") 
public class Bar { 
void bar() { 
    int foo; 
} 
} 

或者只是一種警告:

// This will suppress UnusedLocalVariable warnings in this class 
@SuppressWarnings("PMD.UnusedLocalVariable") 
public class Bar { 
void bar() { 
    int foo; 
} 
} 

,你可能也想看看是什麼creating a ruleset and exclusions。也許你想禁用某個規則,或者從PMD檢查中排除某些文件。