Skip to content

Commit 7bc51de

Browse files
authored
Migrate to public Android Gradle Plugin APIs (#49)
* Migrated: from non-public Android Gradle Plugin APIs to public APIs * Removed: deprecated configurations `skipTestExecution` and `testTypes` (previously deprecated in release 1.4), the reason for removing these now (instead of keeping them deprecated) is that these where depended on non-pubic Android Gradle Plugin classes. * Change: If this plugin applies the JaCoCo plugin, it will no longer show an info message. * Update: Android Gradle Plugin to version 7.2.0-rc01 and some other dependencies * Fix: Use CSVFormat `builder()` instead of deprecated `withHeader()`
1 parent c1dfeca commit 7bc51de

File tree

18 files changed

+267
-377
lines changed

18 files changed

+267
-377
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
uses: actions/checkout@v2
1212
- uses: actions/setup-java@v1
1313
with:
14-
# Robolectric requires Java 11 to compile at Android API level 31
1514
java-version: '11'
1615
- name: test
1716
uses: reactivecircus/android-emulator-runner@v2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ rootCoverage {
144144
# 4. Compatibility
145145
| Version | [Android Gradle plugin version](https://developer.android.com/studio/releases/gradle-plugin#updating-gradle) | Gradle version |
146146
| ------------------ | ------------------------------------------------------------------------------------------------------------ | ----------------- |
147-
| **1.5.0-SNAPSHOT** | 7.2-alpha06 | 7.3+ |
147+
| **1.5.0-SNAPSHOT** | 7.2-rc01 | 7.3+ |
148148
| **See note 2** | 7.0-7.2-alpha05 | n.a. |
149149
| **1.4.0** | 4.2<br/>4.1 | 6.7.1+<br/>6.5+ |
150150
| **1.3.1** | 4.0<br/>3.6 | 6.1.1+<br/>5.6.4+ |

gradle/libs.versions.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ androidMinSdk = "19"
33
androidTargetSdk = "31"
44
androidCompileSdk = "31"
55
kotlin = "1.5.31"
6-
androidGradlePlugin = "7.2.0-beta01"
6+
androidGradlePlugin = "7.2.0-rc01"
77

88
[libraries]
9-
appCompat = { module = "androidx.appcompat:appcompat", version = "1.4.0" }
10-
androidGradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" }
9+
appCompat = { module = "androidx.appcompat:appcompat", version = "1.4.0" }
10+
androidGradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" }
11+
androidGradlePluginApi = { module = "com.android.tools.build:gradle-api", version.ref = "androidGradlePlugin" }
1112

1213
# Test dependencies
1314
junit = { module = "junit:junit", version = "4.13.2" }
1415
truth = { module = "com.google.truth:truth", version = "1.1.3" }
1516
supportTestRunner = { module = "androidx.test:runner", version = "1.4.0" }
1617
espressoCore = { module = "androidx.test.espresso:espresso-core", version = "3.4.0" }
1718
androidJUnit = { module = "androidx.test.ext:junit", version = "1.1.3" }
18-
commonsCsv = { module = "org.apache.commons:commons-csv", version = "1.8" }
19+
commonsCsv = { module = "org.apache.commons:commons-csv", version = "1.9.0" }
1920
kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
2021
robolectric = { module = "org.robolectric:robolectric", version = "4.7.3" }
2122

@@ -28,8 +29,8 @@ jvmTest = ["kotlinTest", "junit", "truth", "commonsCsv"]
2829
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
2930
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
3031
kotlinDokka = { id = "org.jetbrains.dokka", version.ref = "kotlin" }
31-
pluginPortalPublish = { id = "com.gradle.plugin-publish", version = "0.15.0" }
32-
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.18.0" }
32+
pluginPortalPublish = { id = "com.gradle.plugin-publish", version = "0.21.0" }
33+
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.19.0" }
3334
versionCheck = { id = "com.github.ben-manes.versions", version = "0.42.0" }
3435
androidApp = { id = "com.android.application", version.ref = "androidGradlePlugin"}
3536
androidLibrary = { id = "com.android.library", version.ref = "androidGradlePlugin"}

plugin/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ test {
6767

6868
dependencies {
6969
compileOnly gradleApi()
70-
implementation libs.androidGradlePlugin
70+
implementation libs.androidGradlePluginApi
7171

72+
// Without depending on the full Android Gradle Plugin, the test fixture is unable to locate the Android Gradle Plugin.
73+
// Not sure why this is, but for now this is a quick fx to add it to the TestKit classpath.
74+
testImplementation libs.androidGradlePlugin
7275
testImplementation libs.bundles.jvmTest
7376
testImplementation gradleTestKit()
7477
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.neotech.plugin.rootcoverage
2+
3+
import org.gradle.api.Project
4+
import org.gradle.api.file.FileTree
5+
import org.neotech.plugin.rootcoverage.utilities.fileTree
6+
7+
internal fun RootCoveragePluginExtension.getFileFilterPatterns(): List<String> = listOf(
8+
"**/AutoValue_*.*", // Filter to remove generated files from: https://github.com/google/auto
9+
//"**/*JavascriptBridge.class",
10+
11+
// Android Databinding
12+
"**/*databinding",
13+
"**/*binders",
14+
"**/*layouts",
15+
"**/BR.class", // Filter to remove generated databinding files
16+
17+
// Core Android generated class filters
18+
"**/R.class",
19+
"**/R$*.class",
20+
"**/Manifest*.*",
21+
"**/BuildConfig.class",
22+
"android/**/*.*",
23+
24+
"**/*\$ViewBinder*.*",
25+
"**/*\$ViewInjector*.*",
26+
"**/Lambda$*.class",
27+
"**/Lambda.class",
28+
"**/*Lambda.class",
29+
"**/*Lambda*.class",
30+
"**/*\$InjectAdapter.class",
31+
"**/*\$ModuleAdapter.class",
32+
"**/*\$ViewInjector*.class"
33+
) + excludes
34+
35+
internal fun RootCoveragePluginExtension.getBuildVariantFor(project: Project): String =
36+
buildVariantOverrides[project.path] ?: buildVariant
37+
38+
internal fun RootCoveragePluginExtension.getExecutionDataFileTree(project: Project): FileTree {
39+
val buildFolderPatterns = mutableListOf<String>()
40+
if (includeUnitTestResults) {
41+
// TODO instead of hardcoding this, obtain the location from the test tasks, something like this:
42+
// tasks.withType(Test::class.java).all { testTask ->
43+
// testTask.extensions.findByType(JacocoTaskExtension::class.java)?.apply {
44+
// destinationFile
45+
// }
46+
// }
47+
48+
// These are legacy paths for older now unsupported AGP version, they are just here for
49+
// reference and are not added to prevent existing files from polluting results
50+
//
51+
// buildFolderPatterns.add("jacoco/test*UnitTest.exec")
52+
// rootFolderPatterns.add("jacoco.exec") // Note this is not a build folder pattern and is based off project.projectDir
53+
54+
// Android Build Tools Plugin 7.0+
55+
buildFolderPatterns.add("outputs/unit_test_code_coverage/*/*.exec")
56+
}
57+
if (includeAndroidTestResults) {
58+
59+
// These are legacy paths for older now unsupported AGP version, they are just here for
60+
// reference and are not added to prevent existing files from polluting results
61+
//
62+
// Android Build Tools Plugin 3.2
63+
// buildFolderPatterns.add("outputs/code-coverage/connected/*coverage.ec")
64+
//
65+
// Android Build Tools Plugin 3.3-7.0
66+
// buildFolderPatterns.add("outputs/code_coverage/*/connected/*coverage.ec")
67+
68+
// Android Build Tools Plugin 7.1+
69+
buildFolderPatterns.add("outputs/code_coverage/*/connected/*/coverage.ec")
70+
}
71+
return project.fileTree(project.buildDir, includes = buildFolderPatterns)
72+
}

plugin/src/main/kotlin/org/neotech/plugin/rootcoverage/RootCoverageModuleTask.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)