Skip to content

Instantly share code, notes, and snippets.

@ebabel
Created November 22, 2019 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebabel/bef74da2e63ec4f19dbeb3e5910f55b8 to your computer and use it in GitHub Desktop.
Save ebabel/bef74da2e63ec4f19dbeb3e5910f55b8 to your computer and use it in GitHub Desktop.
codecov multi-project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
...
}
repositories {
google()
jcenter()
// Needed for [kotlinter-gradle](https://github.com/jeremymailen/kotlinter-gradle):
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jmailen.gradle:kotlinter-gradle:2.1.0"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
subprojects {
tasks.withType(Test) {
testLogging {
// For more verbosity add: "standardOut", "standardError"
events "passed", "skipped", "failed"
exceptionFormat "full"
showExceptions true
showStackTraces true
showCauses true
}
}
apply from: rootProject.file("quality.gradle")
}
task allTestReport(type: JacocoReport) {
}
afterEvaluate {
allTestReport.dependsOn subprojects*.jacocoReport
}
codecov:
require_ci_to_pass: yes
bot: mobile-bot
coverage:
precision: 2
round: down
range: "0...100"
status:
project: yes
patch: yes
changes: no
parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no
comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no
ignore:
- "src/test"
version: 2
jobs:
build-and-test-android:
working_directory: ~/project
docker:
- image: circleci/android:api-28
environment:
JVM_OPTS: -Xmx1024m
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
TERM: dumb
steps:
- checkout:
path: ~/project
- run:
name: Configure Android SDK Licenses
# Failure to configure the necessary licenses results in the following error during the Gradle build process:
#
# Checking the license for package Android SDK Platform 27 in /opt/android/sdk/licenses
# Warning: License for package Android SDK Platform 27 not accepted.
#
# FAILURE: Build failed with an exception.
#
# * What went wrong:
# A problem occurred configuring project ':app'.
# > You have not accepted the license agreements of the following SDK components:
# [Android SDK Platform 27].
# Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
# Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
command: |
mkdir "$ANDROID_HOME/licenses" || true
echo "x" > "$ANDROID_HOME/licenses/android-sdk-license"
echo "x" >> "$ANDROID_HOME/licenses/android-sdk-license"
- restore_cache:
key: *gradle_cache_key
- run:
name: Kotlinter
command: ./gradlew lintKotlin
- run:
name: Assemble
command: ./gradlew assemble
- save_cache:
paths:
- ~/.gradle
key: *gradle_cache_key
- run:
name: Run Code Coverage
command: |
./gradlew test allTestReport
pip install --user codecov
codecov -t $CODECOV_TOKEN
workflows:
version: 2
build-and-test:
jobs:
- build-and-test-android
apply plugin: "jacoco"
def exclude = [
// Android
'**/R.class',
'**/R$*.class',
'**/Manifest*.*',
'**/BuildConfig.*',
// Android databinding
'**/*databinding/*',
'**/BR.*',
// Dagger
'**/*Dagger*.*',
'**/Dagger*Component.class',
'**/Dagger*Component$Builder.class',
'**/*Module.*',
'**/*MembersInjector*.*',
'**/*_MembersInjector.class',
'**/*_Factory.*',
'**/*Module_*Factory.class',
'**/*_Provide*Factory*.*']
task jacocoReport(type: JacocoReport) {
group "Reporting"
description "Generate Jacoco coverage reports."
reports {
xml.enabled = true
html.enabled = true
}
sourceDirectories = files(["src/main/java"])
classDirectories = (file("$project.buildDir/intermediates/classes/debug").exists()
? fileTree(dir: "$project.buildDir/intermediates/classes/debug", excludes: exclude)
: fileTree(dir: "$project.buildDir/classes", excludes: exclude))
executionData = fileTree(dir: "$project.buildDir", includes: ["jacoco/*.exec"])
}
afterEvaluate {
tasks.findByName("check").dependsOn("jacocoReport")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment