摇篮 1.6 Linux 。
Java构建项目结构
- Project_or_Module
- src/java (包含java源代码)
- test/java(包含 JUnit 测试 - 单元测试)
- src/java-test(包含集成测试)
- etc/etc(项目下的其他 .. .. 文件夹)
我有以下全局配置/build.gradle 文件:
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)
}
对于少数项目,一切正常。即当我运行“gradle clean build”或“gradle clean build jacocoTestReport”时,一切都成功了。
对于其他几个项目,我看到以下问题并需要帮助。
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)
}
错误:A. 任务失败。输出显示如下。
..
....
: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/java-test”文件夹调用上述任务时,会出现错误。
**我的问题 1 **:在 build.gradle 文件中注释了这些行后,我从未看到这些错误,并且“清理构建 jacocoTestReport”任务成功完成,但是当启用 pmd/findbugs/checkstyle 的代码时,我看到了这些错误。为什么要编译 java-test 代码。我以为源代码只在 src/java 下(项目的实际 java 源代码:project_or_module)
B. 另一个项目 ProjectAUtilities 之一在 PMD 步骤中失败,即使在 build.gradle 中为 pmd 忽略错误是正确的。错误说 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。即除了“src/java”文件夹之外,它不会做任何事情。
谢谢。