Gradle PMD Checkstyle Findbugs-使用Java构建哪个源集目录
梯度1.6 Linux Java构建项目结构Gradle PMD Checkstyle Findbugs-使用Java构建哪个源集目录,gradle,ignore,findbugs,checkstyle,pmd,Gradle,Ignore,Findbugs,Checkstyle,Pmd,梯度1.6 Linux Java构建项目结构 项目或模块 src/java(包含java源代码) test/java(包含JUnit测试-单元测试) src/java测试(包含集成测试) etc/etc(项目下的其他…文件夹) 我有以下全局配置/build.gradle文件: apply plugin: 'java' apply plugin: 'pmd' apply plugin: 'findbugs' apply plugin: 'checkstyle'
- 项目或模块
- src/java(包含java源代码)
- test/java(包含JUnit测试-单元测试)
- src/java测试(包含集成测试)
- etc/etc(项目下的其他…文件夹)
apply plugin: 'java'
apply plugin: 'pmd'
apply plugin: 'findbugs'
apply plugin: 'checkstyle'
apply plugin: 'code-quality'
apply plugin: 'jacoco'
tasks.withType(Compile) {
options.debug = true
options.compilerArgs = ["-g"]
}
checkstyle {
configFile = new File(rootDir, "config/checkstyle.xml")
ignoreFailures = true
}
findbugs {
ignoreFailures = true
}
pmd {
ruleSets = ["basic", "braces", "design"]
ignoreFailures = true
}
jacoco {
toolVersion = "0.6.2.201302030002"
reportsDir = file("$buildDir/customJacocoReportDir")
}
sourceSets {
main {
java {
srcDir 'src/java'
}
}
test {
java {
srcDir 'test/java'
}
}
integrationTest {
java {
srcDir 'src/java-test'
}
}
}
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."
reports {
xml{
enabled true
destination "${buildDir}/reports/jacoco/jacoco.xml"
}
csv.enabled false
html{
enabled true
destination "${buildDir}/jacocoHtml"
}
}
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
}
对于少数项目,一切正常。
i、 当我运行“gradle clean build”或“gradle clean build JacoTestReport”时,一切都是成功的
对于其他几个项目,我看到了以下问题,需要帮助
1) “gradle clean build”命令在我删除/注释掉项目的以下行时有效。但是,当这些行像上面显示的代码快照一样未注释时,我会看到错误。下面在代码快照之后提到了错误
apply plugin: 'java'
// apply plugin: 'pmd'
// apply plugin: 'findbugs'
// apply plugin: 'checkstyle'
// apply plugin: 'code-quality'
apply plugin: 'jacoco'
tasks.withType(Compile) {
options.debug = true
options.compilerArgs = ["-g"]
}
// checkstyle {
// configFile = new File(rootDir, "config/checkstyle.xml")
// ignoreFailures = true
// }
// findbugs {
// ignoreFailures = true
// }
// pmd {
// ruleSets = ["basic", "braces", "design"]
// ignoreFailures = true
// }
//
jacoco {
toolVersion = "0.6.2.201302030002"
reportsDir = file("$buildDir/customJacocoReportDir")
}
sourceSets {
main {
java {
srcDir 'src/java'
}
}
test {
java {
srcDir 'test/java'
}
}
integrationTest {
java {
srcDir 'src/java-test'
}
}
}
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."
reports {
xml{
enabled true
destination "${buildDir}/reports/jacoco/jacoco.xml"
}
csv.enabled false
html{
enabled true
destination "${buildDir}/jacocoHtml"
}
}
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
}
错误:
任务失败了。输出显示以下内容
..
....
:compileIntegrationTestJava
/production/jenkinsAKS/jobs/Project_or_Module/workspace/src/java-test/com/tr/ids/application/project_or_module/Project_or_ModuleTestCase.java:11:
package org.apache.cactus does not exist import
org.apache.cactus.ServletTestCase;
^ /production/jenkinsAKS/jobs/Project_or_Module/workspace/src/java-test/com/tr/ids/application/project_or_module/Project_or_ModuleTestCase.java:13:
> cannot find symbol symbol: class ServletTestCase public class
> Project_or_ModuleTestCase extends ServletTestCase
>
...
....
.....
some more errors
...
...
100 errors (similar errors).
您会注意到,当Gradle为“src/javatest”文件夹调用上述任务时,出现了错误
**我的问题1**:在build.gradle文件中注释了这些行之后,我从未看到这些错误,并且“clean build JacoTestReport”任务成功完成,但是当pmd/findbugs/checkstyle的代码启用时,我看到了这些错误。为什么要编译java测试代码。我认为源代码只在src/java下(项目的实际java源代码:project\u或\u模块)
B.另一个项目属性在PMD步骤失败,即使PMD的build.gradle中存在忽略错误。错误显示3次测试失败
错误日志:
20:06:20 :pmdIntegrationTest UP-TO-DATE
20:06:21 :pmdMain
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/pmd/pmd/4.3/pmd-4.3.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/asm/asm/3.2/asm-3.2.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/asm/asm-parent/3.2/asm-parent-3.2.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/junit/junit/4.4/junit-4.4.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/xml-apis/xml-apis/1.3.02/xml-apis-1.3.02.pom
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/pmd/pmd/4.3/pmd-4.3.jar
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/asm/asm/3.2/asm-3.2.jar
20:06:21 Download http://devserver2:8081/artifactory/jcenter-cache/junit/junit/4.4/junit-4.4.jar
20:06:24 251 PMD rule violations were found. See the report at: file:///production/jenkinsAKS/jobs/ProjectAUtilities/workspace/build/reports/pmd/main.html
20:06:26 :pmdTest
20:06:26 16 PMD rule violations were found. See the report at: file:///production/jenkinsAKS/jobs/ProjectAUtilities/workspace/build/reports/pmd/test.html
20:06:26 :test
20:06:26 Download http://devserver2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.pom
20:06:26 Download http://devserver2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.build/0.6.2.201302030002/org.jacoco.build-0.6.2.201302030002.pom
20:06:27 Download http://devserver2:8081/artifactory/jcenter-cache/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.jar
20:06:29 Xlib: connection to "localhost:13.0" refused by server
20:06:29 Xlib: PuTTY X11 proxy: wrong authorisation protocol attempted
20:06:29
20:06:29 com.tr.ids.util.test.chart.TestChartUtilities > getPieChart FAILED
20:06:29 java.lang.InternalError at TestChartUtilities.java:89
20:06:29
20:06:29 com.tr.ids.util.test.chart.TestChartUtilities > getLegend FAILED
20:06:29 java.lang.NoClassDefFoundError at TestChartUtilities.java:103
20:06:29
20:06:29 com.tr.ids.util.test.chart.TestChartUtilities > useString FAILED
20:06:29 java.lang.NoClassDefFoundError at TestChartUtilities.java:143
20:06:29
20:06:29 140 tests completed, 3 failed
20:06:29 :test FAILED
20:06:29
20:06:29 FAILURE: Build failed with an exception.
20:06:29
20:06:29 * What went wrong:
20:06:29 Execution failed for task ':test'.
20:06:29 > There were failing tests. See the report at: file:///production/jenkinsAKS/jobs/ProjectAUtilities/workspace/build/reports/tests/index.html
20:06:29
20:06:29 * Try:
20:06:29 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
20:06:29
20:06:29 BUILD FAILED
我的问题2:我应该为build.gradle中的PMD部分设置什么配置,如果测试失败,该部分将忽略测试。我想我已经有了,也就是说,ignoreFailures=true
C.如何在build.gradle文件(非ANT)中对Checkstyle/PMD/Findbugs使用include/exclude。
i、 除了“src/java”文件夹,它不会去做任何事情
谢谢。以下内容解决了除B(问题2)之外的所有问题即添加了一行源代码集,并告诉这3个工具(pmd/checkstyle/findbugs)在源代码集定义下只查看main(源代码为“src/java”)。顺便说一下,我使用了“sourceset”部分,并在下面几行之前定义了它
checkstyle {
configFile = new File(rootDir, "config/checkstyle.xml")
ignoreFailures = true
sourceSets = [sourceSets.main]
}
findbugs {
ignoreFailures = true
sourceSets = [sourceSets.main]
}
pmd {
ruleSets = ["basic", "braces", "design"]
ignoreFailures = true
sourceSets = [sourceSets.main]
}
上面的代码刚刚创建了checkstyle/findbugs/pmd-check-only src/java(这是我的sourceset.main)。除此之外,问题1的错误在我在build.gradle文件(在项目/模块级别)中包含/提到依赖jar名称后得到了解决。关于Xvfb插件的第二个错误或问题,通过删除Jenkins中的Xvfb插件、重新启动Jenkins并最终清理工作区(即删除Jenkins实例/jobs//workspace/中的所有内容)得到解决。。。。水平