Aru*_*gal 3 testing global file gradle jacoco
概括:
我有几个像 GigaProject 这样的项目。他们都有一个 build.gradle 文件,现在包含以下行,专门用于单元测试的 PMD、CheckStyle、FindBugs 和 Jacoco 代码覆盖率。一切正常。当我运行“gradle clean build”时,项目编译成功并向我显示代码覆盖率报告(jacoco)和 findbugs/checkstyle/pmd 报告。
PNote:我提到过,我没有在此处列出其他用于构建/编译的代码。以下代码只是让 pmd/findbugs/checkstyle 和 Jacoco 功能正常工作的补充。
allprojects {
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")
}
test {
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
}
sourceSets {
main {
java {
srcDir 'src/java'
}
}
test {
java {
srcDir 'test/java'
}
}
integrationTest {
java {
srcDir 'src/java-test'
}
}
}
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)
}
}
Run Code Online (Sandbox Code Playgroud)
我想要的是:不是每个项目都有上面的代码,我想把它从每个项目的 build.gradle 文件中取出,放在 /init.d/commmons 文件下。
即如果您在 /opt/gradle-1.6 安装了 gradle 1.6,那么我想将上述代码添加到 /opt/gradle-1.6/init.d/extra1.common-somename.gradle 文件中。任何存在于 INIT.D 文件夹中的文件首先由 Gradle 读取,所以现在我们不必将上述代码放在每个项目的单独 build.gradle 文件中。
当我在本地 Windows 机器上尝试这种方法时(其中 gradle 存储在 C:\gradle-1.6),我在文件中添加了代码:extra1.common-thids.gradle 并从项目的构建中删除了相同的代码。毕业。只有当我不包含 test { } 和 jacocoTestReport { } 部分时,它才能像代码在项目的 build.gradle 文件中一样成功运行。但是对于这两个,我收到以下错误。
$ gradle clean build
The code-quality plugin HAS BEEN DEPRECATED AND IS SCHEDULED TO BE REMOVED IN GRADLE 2.0. Please use the checkstyle or codenarc plugin instead.
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\gradle-1.6\init.d\extra1.common-thids.gradle' line: 34
* What went wrong:
Failed to notify action.
> org.gradle.api.internal.MissingMethodException: Could not find method test() for arguments [extra1_common_thids_5e0u69jd6ubohvgcf1qr8mhamk$_run_closure1_closure7@56461f58] on build 'GigaProject'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.695 secs
Run Code Online (Sandbox Code Playgroud)
为什么我们选择这样做:这样当开发人员想要运行“gradle build clean”时,他将无法在他的本地构建中看到 pmd/checkstyle/findbugs/jacoco 功能(因为我们会告诉他不要把上面的代码在他的 Gradle 的 init.d 通用文件中)但是当我们从 Jenkins(SCM/CM 团队)运行相同的构建时,然后 Jenkins 服务器的 Gradle-xx/init.d/xxx.common-xxx.gradle 构建文件将包含上述代码,Jenkins 将显示当时的所有功能。
这将帮助开发人员在他们的本地机器上快速构建,Jenkins 会从 pmd/findbugs/checkstyle/jacoco 端向他们展示他们想要的东西。
我需要在通用文件中包含什么才能让我在全局通用文件中包含 test { } 和 jacocoTestReport { } 部分并解决此问题?
非常感谢。
还包括以下行 - 成功了。现在 :) 似乎我可以从项目的特定 build.gradle 文件中删除以下内容。
apply plugin: 'java'
Run Code Online (Sandbox Code Playgroud)
但是,现在 JaCoCo 代码覆盖率报告 index.xml - 在浏览红色/绿色内容的代码覆盖率链接时没有显示文件内容的链接。
| 归档时间: |
|
| 查看次数: |
3547 次 |
| 最近记录: |