When enabling jacoco with gradle kotlin dsl it fails because it looks at build.gradle file instead of build.gradle.kts file.
Here is the error :
##[warning]Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
##[warning]Failed to enable code coverage: Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
app/build.gradle.kts
plugins {
jacoco
}
tasks.withType(JacocoReport::class.java).all {
reports {
xml.isEnabled = true
xml.destination = File("$buildDir/reports/jacoco/report.xml")
}
}
tasks.withType<Test> {
jacoco {
toolVersion = "0.8.3"
reportsDir = file("$buildDir/reports/jacoco")
}
finalizedBy("jacocoTestReport")
}
Azure DevOps task
- task: Gradle#2
displayName: Gradle Build
inputs:
gradleWrapperFile: 'gradlew'
tasks: ':app:assembleDevDebug :networking:lintDebug :app:lintDevDebug --warning-mode all'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
javaHomeOption: 'JDKVersion'
sonarQubeRunAnalysis: false
codeCoverageToolOption: 'jaCoCo'
Messages
##[warning]Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
##[warning]Failed to enable code coverage: Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
are produced by AzureDevOps Gradle Task due to usage of option
codeCoverageToolOption: 'jaCoCo'
in your configuration of this task, because implementation of AzureDevOps Gradle Task contains hardcoded value build.gradle:
https://github.com/Microsoft/azure-pipelines-tasks/blob/9818b165441796437ca881c3f01bd7d90ee6856e/Tasks/GradleV2/gradletask.ts#L66
https://github.com/microsoft/azure-pipelines-tasks/issues/9340
quoting comment from the above bug ticket
The way for you to use code coverage would be to enable it in your build config files and publish them using another task - PublishCodeCoverageResults
Related
I am trying to configure a new Android project to use JaCoCo for test coverage and fail when coverage is below a certain threshold. I have used this documentation, as well as looking at many SO posts. I expect the task to fail, since I don't have test coverage, but it succeeds without any warnings.
My :app build.gradle file includes the following:
plugins {
...
id 'jacoco'
}
jacoco {
toolVersion = "0.8.7"
reportsDirectory = layout.buildDirectory.dir('app/build/reports')
}
task jacocoTestCoverageVerification(type: JacocoCoverageVerification, dependsOn: ['jacocoTestReport']) {
onlyIf = { true }
violationRules {
failOnViolation = true
rule {
limit {
minimum = 1.0
}
}
}
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
finalizedBy jacocoTestCoverageVerification
onlyIf = {true}
reports {
xml.enabled true
html.enabled true
html.outputLocation = layout.buildDirectory.dir('app/build/reports')
}
}
tasks.withType(Test) {
finalizedBy jacocoTestReport
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
android {
...
jacoco{
version = "0.8.7"
}
}
When I try to run tests, using any of the following:
./gradlew test
./gradlew jacocoTestReport
./gradlew jacocoTestCoverageVerification
The results are always the same:
...
> Task :app:connectedDebugAndroidTest
Starting 2 tests on Nexus 5X - 8.1.0
> Task :app:createDebugAndroidTestCoverageReport
> Task :app:createDebugCoverageReport
> Task :app:jacocoTestReport
> Task :app:jacocoTestCoverageVerification
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 31s
93 actionable tasks: 93 executed
Build Analyzer results available
1:10:48 PM: Task execution finished 'test'.
I expect the task to fail, since I have no test coverage. I have added a utility class and method, and partially implemented a test so that the JaCoCo report shows 60% coverage for one class, but this has not changed anything.
I have set up a pipeline that runs my tests in microsoft azure pipelines. On my local machine this works fine and the jetified-libidpmobile-debug.jar file is found in the gradle system directory on my machine:
/Users/jimclermonts/.gradle/caches/transforms-2/files-2.1/efad9765ab457848824459e0c76abddc/jetified-libidpmobile-debug.jar
this is my build.gradle:
debugImplementation files('libs/libidpmobile-debug.jar')
From what I understand, jetified-libidpmobile-debug.jar is automatically created by jetifier from the libidpmobile-debug.jar file.
Output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> Could not resolve all files for configuration ':app:_classStructurekaptDebugKotlin'.
> Failed to transform file 'jetified-libidpmobile-debug.jar' to match attributes {artifactType=class-structure, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}
> Execution failed for StructureArtifactTransform: /Users/iosadmin/.gradle/caches/transforms-2/files-2.1/1e14bb7ec832a0c2c967e6c977ddd9b9/jetified-libidpmobile-debug.jar.
> error in opening zip file
Here is the part of my azure-pipelines.yml that assembles the debug and tests the unit tests:
trigger:
- master
pool:
name: Mobile-Pool
steps:
- task: Gradle#2
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx4096m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'assembleDebug testDebugUnitTest'
I tried the solutions in this post, this post and this post with no result.
The jar file is 4mb big and is the only file that is in the code repository instead of some maven repository.
Updated Gradle to the latest:
classpath 'com.android.tools.build:gradle:4.0.0-beta05'
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Tried to edit the androidmanifest like this:
tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx.core.app.CoreComponentFactory">
build.gradle:
kotlinOptions {
jvmTarget = '1.8'
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
I used jetifier-standalone to jetify the files. Added it to gradle.properties:
android.jetifier.blacklist = libidpmobile
and now it works.
It looks like the databinding issue from the error The following options were not recognized by any processor: '[android.databinding.minApi....
You can try adding below line to build.gradle file.
kapt "com.android.databinding:compiler:$gradle_version"
You can check out below similar threads for more information:
Android Databinding build fail after Gradle plugin update with migration to annotationProcessor
Fail make project if android data binding enabled
Hope above helps!
I am using the Firebase App Distribution with the Gradle plugin.
When I try to run the appDistributionUploadDebug command I receive the error:
Getting appId from output of google services plugin
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:appDistributionUploadDebug'.
> Missing app id
I included the plugin in the build.gradle file
dependencies {
classpath 'com.google.firebase:firebase-appdistribution-gradle:1.2.0'
}
Then I added the config:
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.appdistribution'
android {
//...
debug {
firebaseAppDistribution {
serviceAccountCredentials = "/path/to/your-service-account-key.json"
releaseNotesFile="/path/to/releasenotes.txt"
testers="email#example.com"
}
}
}
If you are not using the google services gradle plugin in your project you have to add the appId property in your configuration.
Something like:
firebaseAppDistribution {
// Firebase App Distribution setup
appId = "...." //<-- add your appID
serviceAccountCredentials = "/path/to/your-service-account-key.json"
releaseNotesFile="/path/to/releasenotes.txt"
testers="email#example.com"
}
You can find the appId value in the google-services.json file
{
...
"client": [
{
"client_info": {
"mobilesdk_app_id": "...",//<-- YOU NEED THIS APP_ID
"android_client_info": {
"package_name": "..."
}
},
...
}
or in the Firebase console on the Project Settings page -> General Tab.
Distribute Android apps to testers using Gradle
Output error on appDistributionVersion 2.0.0:
Could not find the APK. Make sure you build first by running ./gradlew
assemble[Variant]
So that the APK can be found, make sure you build first by running ./gradlew assemble[Variant] and then ./gradlew appDistributionUpload[Variant].
$ ./gradlew assemble[Variant] appDistributionUpload[Variant]
I use FindBugs for static code analysis in my Android projects. The setup is the following:
quality.gradle
plugins.apply('findbugs')
task findbugs(type: FindBugs) {
ignoreFailures = false
effort = 'max'
reportLevel = 'high' // Report only high priority problems.
classes = files("${project.projectDir}/build/intermediates/classes")
source = fileTree('src/main/java')
classpath = files()
reports {
xml.enabled = true
html.enabled = false
}
excludeFilter = rootProject.file('quality/findbugs.xml')
}
build.gradle:
subprojects {
afterEvaluate {
project.apply from: '../quality/quality.gradle'
tasks.findByName('findbugs').dependsOn('assemble')
tasks.findByName('check').dependsOn('findbugs')
}
}
But after I upgraded the Gradle Android Plugin from 3.1.3 to 3.2.0 the build started failing:
./gradlew clean build
> Task :app:findbugs FAILED
No files to be analyzed
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:findbugs'.
> Failed to run Gradle FindBugs Worker
> Process 'Gradle FindBugs Worker 6' finished with non-zero exit value 1
Downgrading to 3.1.3 makes the build pass again. I haven't found anything related in the changelog of the Gradle Android Plugin. Can anybody point me out what's wrong with the plugin or my setup?
After a short investigation, I found out that the location of Java class files has changed from build/intermediates/classes to build/intermediates/javac. The new FindBugs configuration:
task findbugs(type: FindBugs) {
...
classes = files("${project.projectDir}/build/intermediates/javac")
...
}
The strange thing that this breaking change isn't mentioned in the Android Gradle Plugin changelog, or in the Gradle changelog.
Is there any way to run gradle task from app/build.gradle file, so that when I build release APK task "firebaseUploadReleaseProguardMapping" will run automatically.
You can use dependsOn for example (your app/build.gradle):
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-crash'
android {
}
dependencies {
}
task release
task archiveRelease(type: Copy) {
from './build/outputs/apk', './build/outputs/'
into "../releases/${rootProject.ext.configuration.version_code}"
include('app-release.apk', 'mapping/release/mapping.txt')
rename('app-release.apk', "${rootProject.ext.configuration.package}_${rootProject.ext.configuration.version_name}_${rootProject.ext.configuration.version_code}.apk")
}
project.afterEvaluate {
dependencyUpdates.dependsOn clean
assembleRelease.dependsOn clean
def publishApkRelease = project.tasks.getByName("publishApkRelease")
publishApkRelease.dependsOn assembleRelease
release.dependsOn publishApkRelease, firebaseUploadReleaseProguardMapping, archiveRelease
}
I created a new task called release. It depends on publishApkRelease (comes from gradle-play-publisher), firebaseUploadReleaseProguardMapping and archiveRelease. And publishApkRelease depends on assembleRelease.
At the ned you just call ./gradlew release and it will build your release version, uploads the apk to Google play, the mapping file to Firebase and archive a copy of the apk and mapping file.