maven配置checkstyle插件对代码规范进行静态检查

checkstyle配置的官方网站:http://checkstyle.sourceforge.net/config.html

(1)新建maven项目,配置checkstyle插件

pom.xml


  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4.0.0

    cn.demo
    JavademoIn7
    0.0.1-SNAPSHOT
    jar 
    JavademoIn7
    http://maven.apache.org
  
    
        JavademoIn7
        
            
                true
                org.apache.maven.plugins
                maven-compiler-plugin
                3.1
                
                    ${compiler.source}
                    ${compiler.target}
                    ${project.build.sourceEncoding}
                
            
            
    
    
       org.apache.maven.plugins
       maven-checkstyle-plugin
       3.0.0
       
         
           validate
           validate
           
             UTF-8
             true
             true
             false
           
           
             check
           
         
       
     
            
            
              
                org.apache.maven.plugins  
                maven-jar-plugin  
                2.6  
                  
                      
                      
                      
                          
                            cn.demo.JavademoIn7.application.ApplicationMain  
                          
                       
                      
                  
              
            
            
             
               org.apache.maven.plugins 
                maven-assembly-plugin
                2.4.1
                
                    
                        ${project.version}
                        package   
                        
                            single      
                        
                        
                        
                                
                                src/main/resources/script.xml
                            
                            
                            false
                        
                    
                
            
            
        
        
            org.codehaus.mojo
            findbugs-maven-plugin
            3.0.4
            
                
                Low
                
                Medium
                true
                true
                
               
             
            
                
                    run-findbugs
                    
                    install  
                    
                        check
                    
                
            
        
        
        
         
                org.jacoco
                jacoco-maven-plugin
                0.7.8
                
                    
                        prepare-agent
                        
                            prepare-agent
                        
                    
                    
                          check
                        
                            check
                        
                    
                    
                        report
                        prepare-package
                        
                            report
                        
                    
                
                
                
                
                
                
                  
                    BUNDLE
                    
                         
                      
                        METHOD
                        COVEREDRATIO
                        0.50
                      
                        
                      
                        INSTRUCTION
                        COVEREDRATIO
                        0.40
                      
                       
                      
                        LINE
                        COVEREDRATIO
                        0.40
                      
                      
                      
                        CLASS
                        MISSEDCOUNT
                            0
                      
                      
                    
                  
                
                
            
            
    
    
    
    
        
            
               org.apache.maven.plugins
               maven-checkstyle-plugin
               3.0.0
            
        
    
    
        checkstyle.xml 
        UTF-8
        1.7
        1.7
        4.12
    

    
        
            org.jacoco
            jacoco-maven-plugin
            0.7.8
        
        
            org.apache.maven.plugins
            maven-clean-plugin
            2.5
        
        
            junit
            junit
            ${junit.version}
            test
        
            

 

(2)配置checkstyle的规则定义文件

在项目根目录下添加checkstyle.xml文件,内容如下






  
  
    


  
    
    
    
    
    

(3)执行checkstyle:check命令,完成代码规范检查

mvn checkstyle:check  #这条命令发现有错误时会使得构建失败

 

转载于:https://www.cnblogs.com/DFX339/p/8400579.html

你可能感兴趣的:(maven配置checkstyle插件对代码规范进行静态检查)