Skip to content

Commit 1319ca6

Browse files
committed
Commit JaCoCo gradle plugin and example
1 parent 22486fe commit 1319ca6

35 files changed

+839
-0
lines changed

README.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## Introduction
2+
3+
JaCoCo gradle plugin is used to generate code coverage reports for Android project, it creates `JaCoCoReport` task for the variants which `buildType.testCoverageEnabled` is `true`.
4+
5+
## Getting Started
6+
7+
1. Config JaCoCo gradle plugin in `build.gradle` of root project.
8+
9+
```groovy
10+
buildscript {
11+
repositories {
12+
...
13+
jcenter()
14+
}
15+
dependencies {
16+
...
17+
classpath 'com.sdklite.jacoco:gradle:0.1.0'
18+
}
19+
}
20+
```
21+
22+
1. Apply JaCoCo gradle plugin in `build.gradle` of android project
23+
24+
```groovy
25+
apply plugin: 'com.sdklite.jacoco'
26+
27+
android {
28+
...
29+
buildTypes {
30+
debug {
31+
...
32+
testCoverageEnabled true
33+
}
34+
...
35+
}
36+
}
37+
38+
jacocoUnitTestReport {
39+
csv.enabled false
40+
xml.enabled false
41+
html.enabled true
42+
}
43+
```
44+
45+
The plugin excludes Android generated classes from report by default. You can specify custom exclusion patterns by `jacocoUnitTestReport`:
46+
47+
```groovy
48+
jacocoUnitTestReport {
49+
...
50+
excludes += [
51+
'**/AutoValue_*.*',
52+
...
53+
]
54+
}
55+
```
56+
57+
1. Generate coverage report
58+
59+
```bash
60+
$ ./gradlew jacocoTestReport
61+
```
62+
63+
## Example
64+
65+
- [https://github.com/sdklite/jacoco/blob/master/example](./example)
66+

example/.gitignore

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Generated by Mac OS X
2+
.DS_Store
3+
4+
# Generated by VIM
5+
.*.swp
6+
7+
# Generated by Gradle
8+
.gradle
9+
gradle
10+
gradlew
11+
gradlew.bat
12+
13+
# Generated by IDEA
14+
.idea
15+
*.iml
16+
17+
# Generated by Eclipse
18+
.metadata
19+
.settings
20+
.project
21+
.classpath
22+
/bin/
23+
24+
# Generated by Maven
25+
target/
26+
pom.xml.tag
27+
pom.xml.releaseBackup
28+
pom.xml.versionsBackup
29+
pom.xml.next
30+
release.properties
31+
dependency-reduced-pom.xml
32+
buildNumber.properties
33+
.mvn/timing.properties
34+
35+
# Generated by IDE
36+
local.properties
37+
38+
# Misc
39+
*.log
40+
*.bak
41+

example/build.gradle

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
mavenCentral()
5+
google()
6+
jcenter()
7+
}
8+
dependencies {
9+
classpath 'com.android.tools.build:gradle:3.0.0'
10+
classpath 'com.sdklite.jacoco:gradle:0.0.1-SNAPSHOT'
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
mavenLocal()
17+
mavenCentral()
18+
google()
19+
jcenter()
20+
}
21+
}
22+
23+
apply plugin: 'com.android.library'
24+
apply plugin: 'com.sdklite.jacoco'
25+
26+
android {
27+
compileSdkVersion 26
28+
defaultConfig {
29+
minSdkVersion 14
30+
targetSdkVersion 26
31+
versionCode 1
32+
versionName "1.0"
33+
}
34+
buildTypes {
35+
debug {
36+
testCoverageEnabled true
37+
}
38+
release {
39+
minifyEnabled false
40+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
41+
}
42+
}
43+
}
44+
45+
dependencies {
46+
implementation fileTree(dir: 'libs', include: ['*.jar'])
47+
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
48+
testImplementation 'junit:junit:4.12'
49+
androidTestImplementation 'com.android.support.test:runner:0.5'
50+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
51+
}
52+
53+
jacocoUnitTestReport {
54+
csv.enabled false
55+
xml.enabled false
56+
html.enabled true
57+
}
58+

example/gradle.properties

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
org.gradle.jvmargs=-Xmx1536m
13+
14+
# When configured, Gradle will run in incubating parallel mode.
15+
# This option should only be used with decoupled projects. More details, visit
16+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17+
# org.gradle.parallel=true

example/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

example/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.sdklite.jacoco.example">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.sdklite.jacoco.example;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
6+
public class MainActivity extends AppCompatActivity {
7+
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportHeight="108"
6+
android:viewportWidth="108">
7+
<path
8+
android:fillType="evenOdd"
9+
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
10+
android:strokeColor="#00000000"
11+
android:strokeWidth="1">
12+
<aapt:attr name="android:fillColor">
13+
<gradient
14+
android:endX="78.5885"
15+
android:endY="90.9159"
16+
android:startX="48.7653"
17+
android:startY="61.0927"
18+
android:type="linear">
19+
<item
20+
android:color="#44000000"
21+
android:offset="0.0" />
22+
<item
23+
android:color="#00000000"
24+
android:offset="1.0" />
25+
</gradient>
26+
</aapt:attr>
27+
</path>
28+
<path
29+
android:fillColor="#FFFFFF"
30+
android:fillType="nonZero"
31+
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
32+
android:strokeColor="#00000000"
33+
android:strokeWidth="1" />
34+
</vector>

0 commit comments

Comments
 (0)