Skip to content

Commit 9a0626c

Browse files
committed
Update readme and fix template generation
1 parent fa5a17b commit 9a0626c

File tree

4 files changed

+102
-78
lines changed

4 files changed

+102
-78
lines changed

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-->
66
# <img src=".images/logo.png" align="right" width="100">android-junit5 [![CircleCI](https://circleci.com/gh/mannodermaus/android-junit5/tree/main.svg?style=svg)][circleci]
77

8-
A Gradle plugin that allows for the execution of [JUnit 5][junit5gh] tests in Android environments using **Android Gradle Plugin 8.0.0 or later.**
8+
A Gradle plugin that allows for the execution of [JUnit 5][junit5gh] tests in Android environments using **Android Gradle Plugin 8.2 or later.**
99

1010
## How?
1111

@@ -22,20 +22,20 @@ To get started, declare the plugin in your `app` module's build script alongside
2222

2323
```kotlin
2424
plugins {
25-
id("de.mannodermaus.android-junit5") version "1.12.2.0"
25+
id("de.mannodermaus.android-junit5") version "1.13.0.0"
2626
}
2727

2828
dependencies {
2929
// (Required) Writing and executing Unit Tests on the JUnit Platform
30-
testImplementation("org.junit.jupiter:junit-jupiter-api:5.12.2")
31-
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.12.2")
30+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.13.0")
31+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.13.0")
3232

3333
// (Optional) If you need "Parameterized Tests"
34-
testImplementation("org.junit.jupiter:junit-jupiter-params:5.12.2")
34+
testImplementation("org.junit.jupiter:junit-jupiter-params:5.13.0")
3535

3636
// (Optional) If you also have JUnit 4-based tests
3737
testImplementation("junit:junit:4.13.2")
38-
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.12.2")
38+
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.13.0")
3939
}
4040
```
4141
</details>
@@ -45,20 +45,20 @@ To get started, declare the plugin in your `app` module's build script alongside
4545

4646
```groovy
4747
plugins {
48-
id "de.mannodermaus.android-junit5" version "1.12.2.0"
48+
id "de.mannodermaus.android-junit5" version "1.13.0.0"
4949
}
5050
5151
dependencies {
5252
// (Required) Writing and executing Unit Tests on the JUnit Platform
53-
testImplementation "org.junit.jupiter:junit-jupiter-api:5.12.2"
54-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.12.2"
53+
testImplementation "org.junit.jupiter:junit-jupiter-api:5.13.0"
54+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.13.0"
5555
5656
// (Optional) If you need "Parameterized Tests"
57-
testImplementation "org.junit.jupiter:junit-jupiter-params:5.12.2"
57+
testImplementation "org.junit.jupiter:junit-jupiter-params:5.13.0"
5858
5959
// (Optional) If you also have JUnit 4-based tests
6060
testImplementation "junit:junit:4.13.2"
61-
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.12.2"
61+
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.13.0"
6262
}
6363
```
6464
</details>
@@ -76,7 +76,7 @@ If you prefer to use the legacy way to declare the dependency instead, remove th
7676
// In the root project's build.gradle.kts:
7777
buildscript {
7878
dependencies {
79-
classpath("de.mannodermaus.gradle.plugins:android-junit5:1.12.2.0")
79+
classpath("de.mannodermaus.gradle.plugins:android-junit5:1.13.0.0")
8080
}
8181
}
8282

@@ -94,7 +94,7 @@ If you prefer to use the legacy way to declare the dependency instead, remove th
9494
// In the root project's build.gradle:
9595
buildscript {
9696
dependencies {
97-
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.12.2.0"
97+
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.13.0.0"
9898
}
9999
}
100100
@@ -110,8 +110,8 @@ More information on Getting Started can be found [on the wiki][wiki-gettingstart
110110
## Requirements
111111

112112
The latest version of this plugin requires:
113-
* Android Gradle Plugin `8.0.0` or above
114-
* Gradle `8.0` or above
113+
* Android Gradle Plugin `8.2` or above
114+
* Gradle `8.2` or above
115115

116116
## Instrumentation Test Support
117117

@@ -124,7 +124,7 @@ Before you can write instrumentation tests with JUnit Jupiter, make sure that yo
124124

125125
```kotlin
126126
dependencies {
127-
androidTestImplementation("org.junit.jupiter:junit-jupiter-api:5.12.2")
127+
androidTestImplementation("org.junit.jupiter:junit-jupiter-api:5.13.0")
128128
}
129129
```
130130
</details>
@@ -134,7 +134,7 @@ Before you can write instrumentation tests with JUnit Jupiter, make sure that yo
134134

135135
```groovy
136136
dependencies {
137-
androidTestImplementation "org.junit.jupiter:junit-jupiter-api:5.12.2"
137+
androidTestImplementation "org.junit.jupiter:junit-jupiter-api:5.13.0"
138138
}
139139
```
140140
</details>
@@ -216,7 +216,7 @@ when it sets up the artifacts automatically. However, it is possible to choose a
216216

217217
```kotlin
218218
junitPlatform {
219-
instrumentationTests.version.set("1.7.0")
219+
instrumentationTests.version.set("1.8.0")
220220
}
221221
```
222222
</details>
@@ -226,7 +226,7 @@ when it sets up the artifacts automatically. However, it is possible to choose a
226226

227227
```groovy
228228
junitPlatform {
229-
instrumentationTests.version.set("1.7.0")
229+
instrumentationTests.version.set("1.8.0")
230230
}
231231
```
232232
</details>
@@ -280,12 +280,13 @@ This repository contains multiple modules, divided into two sub-projects. The re
280280

281281
For users that cannot match the current minimum version requirement of the Android Gradle Plugin requested by this plugin,
282282
refer to the table below to find a suitable alternative version. Note that **no active development will go into these
283-
legacy versions**, so please consider upgrading to at least Android Gradle Plugin 8.0.0
283+
legacy versions**, so please consider upgrading to at least Android Gradle Plugin 8.2
284284
before filing an issue with the latest one.
285285

286286
|Your AGP Version|Suggested JUnit5 Plugin Version|
287287
|---|---|
288-
|`>= 8.0.0`|`1.12.2.0`|
288+
|`>= 8.2.0`|`1.13.0.0`|
289+
|`8.0.0` - `8.1.4`|`1.12.2.0`|
289290
|`7.0.0` - `7.4.2`|`1.10.0.0`|
290291
|`4.0.0` - `4.2.2`|`1.8.2.1`|
291292
|`3.5.0` - `3.6.4`|`1.7.1.1`|

build-logic/src/main/kotlin/Environment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ object Artifacts {
9191
platform = Java,
9292
groupId = "de.mannodermaus.gradle.plugins",
9393
artifactId = "android-junit5",
94-
currentVersion = "1.13.0.0",
95-
latestStableVersion = "1.12.2.0",
94+
currentVersion = "1.13.1.0-SNAPSHOT",
95+
latestStableVersion = "1.13.0.0",
9696
description = "Unit Testing with JUnit 5 for Android."
9797
)
9898

build-logic/src/main/kotlin/Tasks.kt

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ import org.gradle.api.attributes.plugin.GradlePluginApiVersion
1212
import org.gradle.api.attributes.plugin.GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE
1313
import org.gradle.api.file.DuplicatesStrategy
1414
import org.gradle.api.file.RegularFileProperty
15-
import org.gradle.api.tasks.*
15+
import org.gradle.api.tasks.Copy
16+
import org.gradle.api.tasks.InputFile
17+
import org.gradle.api.tasks.OutputFile
18+
import org.gradle.api.tasks.SourceSetContainer
19+
import org.gradle.api.tasks.TaskAction
1620
import java.io.File
1721
import java.time.ZonedDateTime
18-
import java.util.*
22+
import java.util.Locale
1923

2024
private const val minimumGradleVersion = "8.2"
2125

@@ -25,38 +29,38 @@ fun Project.configureTestResources() {
2529
// for different versions of the Android Gradle Plugin
2630
tasks.named("processTestResources", Copy::class.java).configure {
2731
val tokens = mapOf(
28-
"COMPILE_SDK_VERSION" to Android.compileSdkVersion.toString(),
29-
"MIN_SDK_VERSION" to Android.sampleMinSdkVersion.toString(),
30-
"TARGET_SDK_VERSION" to Android.targetSdkVersion.toString(),
31-
32-
"KOTLIN_VERSION" to libs.versions.kotlin,
33-
"JUNIT_JUPITER_VERSION" to libs.versions.junitJupiter,
34-
"JUNIT5_ANDROID_LIBS_VERSION" to Artifacts.Instrumentation.Core.latestStableVersion,
35-
36-
// Collect all supported AGP versions into a single string.
37-
// This string is delimited with semicolons, and each of the separated values itself is a 4-tuple.
38-
//
39-
// Example:
40-
// AGP_VERSIONS = 3.5|3.5.3|;3.6|3.6.3|6.4;3.7|3.7.0|8.0|33
41-
//
42-
// Can be parsed into this list of values:
43-
// |___> Short: "3.5"
44-
// Full: "3.5.3"
45-
// Gradle Requirement: ""
46-
// Compile SDK: null
47-
//
48-
// |___> Short: "3.6"
49-
// Full: "3.6.3"
50-
// Gradle Requirement: "6.4"
51-
// Compile SDK: null
52-
//
53-
// |___> Short: "3.7"
54-
// Full: "3.7.0"
55-
// Gradle Requirement: "8.0"
56-
// Compile SDK: 33
57-
"AGP_VERSIONS" to SupportedAgp.values().joinToString(separator = ";") { plugin ->
58-
"${plugin.shortVersion}|${plugin.version}|${plugin.gradle}|${plugin.compileSdk ?: ""}"
59-
}
32+
"COMPILE_SDK_VERSION" to Android.compileSdkVersion.toString(),
33+
"MIN_SDK_VERSION" to Android.sampleMinSdkVersion.toString(),
34+
"TARGET_SDK_VERSION" to Android.targetSdkVersion.toString(),
35+
36+
"KOTLIN_VERSION" to libs.versions.kotlin,
37+
"JUNIT_JUPITER_VERSION" to libs.versions.junitJupiter,
38+
"JUNIT5_ANDROID_LIBS_VERSION" to Artifacts.Instrumentation.Core.latestStableVersion,
39+
40+
// Collect all supported AGP versions into a single string.
41+
// This string is delimited with semicolons, and each of the separated values itself is a 4-tuple.
42+
//
43+
// Example:
44+
// AGP_VERSIONS = 3.5|3.5.3|;3.6|3.6.3|6.4;3.7|3.7.0|8.0|33
45+
//
46+
// Can be parsed into this list of values:
47+
// |___> Short: "3.5"
48+
// Full: "3.5.3"
49+
// Gradle Requirement: ""
50+
// Compile SDK: null
51+
//
52+
// |___> Short: "3.6"
53+
// Full: "3.6.3"
54+
// Gradle Requirement: "6.4"
55+
// Compile SDK: null
56+
//
57+
// |___> Short: "3.7"
58+
// Full: "3.7.0"
59+
// Gradle Requirement: "8.0"
60+
// Compile SDK: 33
61+
"AGP_VERSIONS" to SupportedAgp.values().joinToString(separator = ";") { plugin ->
62+
"${plugin.shortVersion}|${plugin.version}|${plugin.gradle}|${plugin.compileSdk ?: ""}"
63+
}
6064
)
6165

6266
inputs.properties(tokens)
@@ -125,17 +129,19 @@ fun Project.configureTestResources() {
125129
// 2) Use resources from the plugin (i.e. plugin IDs etc.)
126130
// 3) Use AGP-specific dependencies
127131
val classesDirs = file("$buildDir/classes").listFiles()
128-
?.filter { it.isDirectory }
129-
?.map { File(it, "main") }
130-
?.filter { it.exists() && it.isDirectory && it.list()?.isEmpty() == false }
131-
?: emptyList()
132+
?.filter { it.isDirectory }
133+
?.map { File(it, "main") }
134+
?.filter { it.exists() && it.isDirectory && it.list()?.isEmpty() == false }
135+
?: emptyList()
132136
val resourcesDirs = file("$buildDir/resources").listFiles()
133-
?.filter { it.isDirectory }
134-
?: emptyList()
137+
?.filter { it.isDirectory }
138+
?: emptyList()
135139

136140
writer.write("implementation-classpath=")
137-
writer.write((classesDirs + resourcesDirs + configuration)
138-
.joinToString(separator = "\\:"))
141+
writer.write(
142+
(classesDirs + resourcesDirs + configuration)
143+
.joinToString(separator = "\\:")
144+
)
139145
}
140146
}
141147
}
@@ -146,7 +152,7 @@ fun findInstrumentationVersion(
146152
pluginVersion: String = Artifacts.Plugin.currentVersion,
147153
currentInstrumentationVersion: String = Artifacts.Instrumentation.Core.currentVersion,
148154
stableInstrumentationVersion: String = Artifacts.Instrumentation.Core.latestStableVersion
149-
): String {
155+
): String {
150156
return when {
151157
pluginVersion.endsWith("-SNAPSHOT") -> currentInstrumentationVersion
152158
currentInstrumentationVersion.endsWith("-SNAPSHOT") -> stableInstrumentationVersion
@@ -197,12 +203,14 @@ abstract class GenerateReadme : DefaultTask() {
197203
private const val PLUGIN_VERSION = "pluginVersion"
198204
private const val INSTRUMENTATION_VERSION = "instrumentationVersion"
199205

200-
private const val CONSTANTS_FILE = "android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/internal/config/Constants.kt"
201-
private val CONSTANTS_FILE_REGEX = Regex("const val (.*) = \"(.*)\"")
206+
private const val CONSTANTS_FILE =
207+
"android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/internal/config/Constants.kt"
208+
private val CONSTANTS_FILE_REGEX1 = Regex("""val (.*)\s*=\s*.+"(.*)".+""")
209+
private val CONSTANTS_FILE_REGEX2 = Regex("""val (.*)\s*=\s*AndroidPluginVersion\((\d+)\s*,\s*(\d+)\)""")
202210
private val CONSTANT_MAPPINGS = mapOf(
203-
"minimumRequiredGradleVersion" to "MIN_REQUIRED_GRADLE_VERSION",
204-
"minimumRequiredAgpVersion" to "MIN_REQUIRED_AGP_VERSION",
205-
"currentYear" to "CURRENT_YEAR",
211+
"minimumRequiredGradleVersion" to "MIN_REQUIRED_GRADLE_VERSION",
212+
"minimumRequiredAgpVersion" to "MIN_REQUIRED_AGP_VERSION",
213+
"currentYear" to "CURRENT_YEAR",
206214
)
207215

208216
private val GENERATED_HEADER_COMMENT = """
@@ -241,7 +249,7 @@ abstract class GenerateReadme : DefaultTask() {
241249

242250
PLACEHOLDER_REGEX.findAll(templateText).forEach { match ->
243251
val placeholder = match.groups.last()?.value
244-
?: throw InvalidPlaceholder(match)
252+
?: throw InvalidPlaceholder(match)
245253

246254
// Local versions (plugin, instrumentation)
247255
val replacement = when (placeholder) {
@@ -251,14 +259,16 @@ abstract class GenerateReadme : DefaultTask() {
251259
val match2 = CONSTANT_REGEX.find(placeholder)
252260
if (match2 != null) {
253261
val key = match2.groups.last()?.value
262+
val constantKey1 = CONSTANT_MAPPINGS[key]
263+
println("Constant key. placeholder=$placeholder, match2=$match2, constantKey1=$constantKey1, constants=$constants")
254264
val constantKey = CONSTANT_MAPPINGS[key] ?: throw InvalidPlaceholder(match2)
255265
constants[constantKey] ?: throw InvalidPlaceholder(match2)
256266

257267
} else {
258268
val match3 = EXTERNAL_DEP_REGEX.find(placeholder)
259-
?: throw InvalidPlaceholder(match)
269+
?: throw InvalidPlaceholder(match)
260270
val externalDependency = match3.groups.last()?.value
261-
?: throw InvalidPlaceholder(match3)
271+
?: throw InvalidPlaceholder(match3)
262272

263273
val field = libs.javaClass.getField(externalDependency)
264274
field.get(null) as String
@@ -284,15 +294,27 @@ abstract class GenerateReadme : DefaultTask() {
284294
// Add hardcoded constants
285295
constants["CURRENT_YEAR"] = ZonedDateTime.now().year.toString()
286296

287-
CONSTANTS_FILE_REGEX.findAll(text).forEach { match ->
288-
constants[match.groups[1]!!.value] = match.groups[2]!!.value
297+
CONSTANTS_FILE_REGEX1.findAll(text).forEach { match ->
298+
constants[match[1]] = match[2]
299+
}
300+
301+
// Special case for AGP version
302+
CONSTANTS_FILE_REGEX2.findAll(text).forEach { match ->
303+
constants[match[1]] = match.groupValues
304+
.drop(2)
305+
.joinToString(separator = ".", transform = String::trim)
289306
}
290307

291308
return constants
292309
}
310+
311+
private operator fun MatchResult.get(index: Int): String {
312+
return this.groups[index]!!.value.trim()
313+
}
293314
}
294315

295-
private class InvalidPlaceholder(matchResult: MatchResult) : Exception("Invalid match result: '${matchResult.groupValues}'")
316+
private class InvalidPlaceholder(matchResult: MatchResult) :
317+
Exception("Invalid match result: '${matchResult.groupValues}'")
296318

297319
private val Deployed.anyStableVersion: String
298320
get() = if (currentVersion.endsWith("-SNAPSHOT")) {

plugin/android-junit5/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
22
import org.gradle.api.tasks.testing.logging.TestLogEvent
33
import org.jetbrains.dokka.gradle.DokkaTask
4+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
45
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
56

67
plugins {
@@ -22,7 +23,7 @@ plugins {
2223
// ------------------------------------------------------------------------------------------------
2324
val javaVersion = JavaVersion.VERSION_11.toString()
2425
tasks.withType<KotlinCompile> {
25-
kotlinOptions.jvmTarget = javaVersion
26+
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(javaVersion))
2627
}
2728
tasks.withType<JavaCompile> {
2829
sourceCompatibility = javaVersion

0 commit comments

Comments
 (0)