在gradle脚本中检查checkstyle插件中的问题

时间:2015-04-19 06:26:28

标签: gradle build.gradle checkstyle

下面是我的gradle脚本,我正在尝试使用checkstyle插件,但在使用它时遇到了一些问题。

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'findbugs'
apply plugin: 'pmd'
apply plugin: 'checkstyle'

//-- set the group for publishing
group = 'com.rohit.singh'

/**
 * Initializing GAVC settings
 */
def buildProperties = new Properties()
file("version.properties").withInputStream { 
    stream -> buildProperties.load(stream) 
} 
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.engineBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.engineBuildVersion
println "${version}"

//name is set in the settings.gradle file
group = "com.xxxx.engine"
version = buildProperties.engineBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"

sourceCompatibility = 1.6
jar {
   manifest {
       attributes 'Implementation-Title': "${project.name}",
                   'Implementation-Version': "${project.version}",
                   'Implementation-Vendor-Id': "${project.group}"
                  }
}                
  repositories {

    maven {
      url "http://xjhxxxx.xxxx.xxxxx.com:99999/artifactory/repo1-cache"
    }
  }

dependencies {
    compile ([
    "com.eaio.uuid:uuid:3.2",
    "org.springframework:spring-context:2.5.6",
    "org.springframework:spring-beans:1.2.6" ,
    "org.springframework:spring-core:1.2.3",
    "org.springframework:spring-aop:3.0.6.RELEASE",
    "org.springframework:spring-expression:3.0.7.RELEASE",
    "org.projectlombok:lombok:1.12.2",
    "com.fasterxml.jackson.core:jackson-core:2.1.3",
    "com.fasterxml.jackson.core:jackson-annotations:2.2.3",
    "com.fasterxml.jackson.core:jackson-databind:2.2.3",
    "org.slf4j:slf4j-api:1.7.6",
    "org.apache.commons:commons-lang3:3.0",
    "junit:junit:4.+"
      ])
}

jacoco {
    toolVersion = "0.7.1.201405082137"
}
test {
    jacoco {
        append = false
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
        classDumpFile = file("$buildDir/jacoco/classpathdumps")
    }
}

jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    executionData = fileTree(dir: 'build/jacoco', include: '**/*.exec')

    reports {
        xml{
            enabled true
            //Following value is a file
            destination "${buildDir}/reports/jacoco/xml/jacoco.xml"
        }
        csv.enabled false
     html{
       enabled true
       //Following value is a folder
       destination "${buildDir}/reports/jacoco/html"
     }
    }
}

findbugs {
        ignoreFailures = true
       //sourceSets = [sourceSets.main]
   }

pmd { 
         ruleSets = ["java-basic", "java-braces", "java-design"] 
         ignoreFailures = true
         //sourceSets = [sourceSets.main]
   }

checkstyle {
       configFile = new File(rootDir, "config/checkstyle/checkstyle.xml")
       ignoreFailures = true
       sourceSets = [sourceSets.main]
   }

// adding test report to taskGraph
build.dependsOn checkstyleReport

// ------ Publish the jar file to artifactory ------
artifacts {
  archives jar
}

输出:

  
    

无法创建检查器:无法找到C:\ MERCURIAL_WORKSPACE \ Common \ confi g \ checkstyle \ checkstyle.xml

  

1 个答案:

答案 0 :(得分:0)

您所指的位置可能没有checkstyle.xml。在$projectRoot/config/checkstyle/checkstyle.xml中创建一个简单的配置文件,然后尝试构建。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
    "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
     "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter"/>
  <module name="TreeWalker">
    <module name="UnusedImports"/>
  </module>
</module>

稍后添加更多模块/规则集。