Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: android
android:
components:
- android-28
- build-tools-27.0.3

env:
global:
# install timeout in minutes (2 minutes by default)
- ADB_INSTALL_TIMEOUT=8

# Run assemble, unit tests, and create coverage report
script:
- ./gradlew clean assembleDebug assembleRelease testDebug createDebugUnitTestCoverageReport
# Renaming folder and files of reports so codecov.io can find it
- mv app/build/reports/jacoco/createDebugUnitTestCoverageReport app/build/reports/jacoco/jacocoTestDebugUnitTestReport
- mv app/build/reports/jacoco/jacocoTestDebugUnitTestReport/createDebugUnitTestCoverageReport.xml app/build/reports/jacoco/jacocoTestDebugUnitTestReport/jacocoTestDebugUnitTestReport.xml
# Codecov.io
- bash <(curl -s https://codecov.io/bash)
68 changes: 68 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'jacoco-android'

android {
compileSdkVersion 28
Expand Down Expand Up @@ -76,3 +77,70 @@ dependencies {
// Android Arch Core Testing
testImplementation 'android.arch.core:core-testing:1.1.1'
}

project.afterEvaluate {
//Gather build type and product flavor names in a list
def buildTypes = android.buildTypes.collect { type -> type.name }
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
if (!productFlavors) productFlavors.add('')

productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->

//Define the sourceName and the sourcePath.
def sourceName, sourcePath
if (!productFlavorName) {
sourceName = sourcePath = "${buildTypeName}"
} else {
sourceName = "${productFlavorName}${buildTypeName.capitalize()}"
sourcePath = "${productFlavorName}/${buildTypeName}"
}

def testTaskName = "test${sourceName.capitalize()}UnitTest"

task "create${sourceName.capitalize()}UnitTestCoverageReport"(type: JacocoReport, dependsOn: "$testTaskName") {

group = "Reporting"
description =
"Generate Jacoco coverage reports on the ${sourceName.capitalize()} build."

reports {
xml.enabled true
html.enabled true
}

//Directory where the compiled class files are
classDirectories =
fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/${sourcePath}",
excludes: ['**/R.class',
'**/BR.class',
// Remove Activity and application as they are dependent to Context
'**/*Activity.class',
'**/net/gahfy/mvvmposts/injection/ViewModelFactory.class',
// Remove View Utils
'**/net/gahfy/mvvmposts/utils/extension/ViewExtension.class',
'**/net/gahfy/mvvmposts/utils/BindingAdapters.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'android/**',
'**/Manifest*.*',
'**/*$Lambda$*.*', // Jacoco can not handle several "$" in class name.
'**/*Module.*', // Modules for Dagger.
'**/*Dagger*.*', // Dagger auto-generated code.
'**/*MembersInjector*.*', // Dagger auto-generated code.
'**/*_Provide*Factory*.*',
'**/*_Factory.*', //Dagger auto-generated code
'**/*$*$*.*' // Anonymous classes generated by kotlin
])

sourceDirectories = files(["src/main/kotlin",
"src/$productFlavorName/kotlin",
"src/$buildTypeName/kotlin"])

executionData = files("${project.buildDir}/jacoco/${testTaskName}.exec")
}
}
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
1 change: 1 addition & 0 deletions readme.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[![Build Status](https://travis-ci.org/gahfy/MVVMPosts.svg?branch=continuous_integration)](https://travis-ci.org/gahfy/MVVMPosts) [![Codecov](https://codecov.io/github/gahfy/MVVMPosts/coverage.svg?branch=continuous_integration)](https://codecov.io/gh/gahfy/MVVMPosts)