【问题标题】:Getting issue in checkstyle plugin in gradle script在 gradle 脚本中出现 checkstyle 插件的问题
【发布时间】:2015-04-19 06:26:28
【问题描述】:

以下是我的 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\config\checkstyle\checkstyle.xml

【问题讨论】:

    标签: gradle build.gradle checkstyle


    【解决方案1】:

    您所指的位置可能没有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>
    

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

    【讨论】:

    • 感谢您回答问题。我已经修复了。是的,您是正确的,缺少的部分是 checkstyle.xml 文件。我在 config 文件夹下创建了它,然后再次运行它。
    猜你喜欢
    • 2016-05-18
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多