gpt4 book ai didi

android - Gradle JacocoTestReports 任务在 bamboo 构建服务器上被跳过,但在本地机器上构建良好

转载 作者:太空宇宙 更新时间:2023-11-03 10:18:39 26 4
gpt4 key购买 nike

我有一个 gradle 脚本,其中包含一个使用 Jacoco 进行报告的测试任务。 build.gradle 看起来像这样:

buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
}
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
apply plugin: "sonar-runner"

repositories {
maven { url 'https://maven.fabric.io/public' }
}

android {
compileSdkVersion 21
buildToolsVersion '22.0.1'

defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"

testHandleProfiling true
testFunctionalTest true
}

buildTypes {
debug {
applicationIdSuffix ".debug"
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
apply plugin: 'android-unit-test'

dependencies {
testCompile 'org.easytesting:fest:1.0.16'
testCompile 'junit:junit:4.10'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'com.squareup:fest-android:1.0.8'
}
}

def coverageSourceDirs = [
'../app/src/main/java', 'src/gen'
]

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}

classDirectories = fileTree(
dir: './build/intermediates/classes/debug',
excludes: ['**/R.class',
'**/R$*.class'
])
sourceDirectories = files(coverageSourceDirs)
executionData = files('build/jacoco/testDebug.exec')
}

sonarRunner {

sonarProperties {

property "sonar.projectKey", "coverage-example"
property "sonar.projectName", "Coverage Example"
property "sonar.projectVersion", "1.0"

property "sonar.sources", "src/main/java"
property "sonar.binaries", "build"
property "sonar.test", "src/test/java"

property "sonar.language", "java"
property "sonar.profile", "Android Lint"
property "sonar.android.lint.report", "lint-report.xml"
property "sonar.dynamicAnalysis", "reuseReports"
property "sonar.sourceEncoding", "UTF-8"

property "sonar.junit.reportsPath", "build/outputs/reports/coverage/debug"
property "sonar.cobertura.reportPath", "build/outputs/reports/coverage/debug/cobertura.xml"
property "sonar.java.coveragePlugin", "cobertura"

property "sonar.host.url", "https://sonar.domain.com"

property "sonar.jdbc.url", "jdbc:mysql://sonar.domain.com:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance"

property "sonar.jdbc.username", "someuser"
property "sonar.jdbc.password", "somepass"
}

}

在本地机器上运行所有测试,我得到了预期的报告。但是在 bamboo 服务器上运行我可以在日志中看到任务被跳过:

build   05-May-2015 16:19:24    :app:validateDebugSigning
build 05-May-2015 16:19:25 :app:packageDebug
build 05-May-2015 16:19:25 :app:zipalignDebug
build 05-May-2015 16:19:25 :app:assembleDebug
build 05-May-2015 16:19:25 :app:compileTestDebugJava
build 05-May-2015 16:19:25 :app:processTestDebugResources UP-TO-DATE
build 05-May-2015 16:19:25 :app:testDebugClasses
build 05-May-2015 16:19:25 :app:testDebug
build 05-May-2015 16:19:25 :app:jacocoTestReport SKIPPED
build 05-May-2015 16:19:26 :app:sonarRunner
build 05-May-2015 16:19:26 SonarQube Runner 2.3
build 05-May-2015 16:19:26 Java 1.7.0_79 Oracle Corporation (64-bit)
build 05-May-2015 16:19:26 Linux 3.13.0-46-generic amd64
build 05-May-2015 16:19:26 INFO: Runner configuration file: NONE
build 05-May-2015 16:19:26 INFO: Project configuration file: /bamboo/xml-data/build-dir/TSTIOSAPPA-TP-BDA/app/build/tmp/sonarRunner/sonar-project.properties
build 05-May-2015 16:19:26 INFO: Default locale: "en_US", source code encoding: "UTF-8"
build 05-May-2015 16:19:26 INFO: Work directory: /bamboo/xml-data/build-dir/TSTIOSAPPA-TP-BDA/app/build/sonar
build 05-May-2015 16:19:26 INFO: SonarQube Server 5.1

由于我没有收到任何错误,所以我不明白问题出在哪里。 Gradle 使用 gradle-wrapper 执行,因此它在两台机器上使用相同的版本构建。有任何想法吗?

编辑:

我看过Running jacocoReport ,但这并不能真正解释为什么它在我的本地机器上运行而不在构建服务器上运行。如果我添加测试任务(使用 java 插件),我会收到以下错误:

The 'java' plugin has been applied, but it is not compatible with the Android plugins.

如果我不应用 java 插件,我会收到以下错误:

Could not find method test() for arguments [build_58yd8leqt3uhm31fecj9zk2qm$_run_closure4@3a73cd3f] on project ':app'.

但也许我完全误解了如何使用测试任务?在项目“:app”上找不到参数 [build_58yd8leqt3uhm31fecj9zk2qm$_run_closure4@3a73cd3f] 的方法 test()。

最佳答案

当没有要处理的覆盖率数据时,将跳过 jacocoTestReport 任务。

覆盖率数据是在运行测试时产生的。在 android 上,任务 androidTest 将执行测试。

要生成 jacoco 报告,您必须使用如下一行运行测试:

.\gradlew androidTest

关于android - Gradle JacocoTestReports 任务在 bamboo 构建服务器上被跳过,但在本地机器上构建良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30057573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com