Skip to content

Commit 05138af

Browse files
committed
Use correct bundled version of instrumentation libraries for the plugin
1 parent 220f5b8 commit 05138af

File tree

10 files changed

+127
-50
lines changed

10 files changed

+127
-50
lines changed

.circleci/config.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defaults: &defaults
88
GRADLE_OPTS: -Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dorg.gradle.daemon=false -Dorg.gradle.caching=true -Dorg.gradle.configureondemand=true -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false
99

1010
cache_key: &cache_key
11-
key: jars-{{ checksum "plugin/build.gradle.kts" }}-{{ checksum "plugin/android-junit5/build.gradle.kts" }}-{{ checksum "plugin/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "instrumentation/build.gradle.kts" }}-{{ checksum "instrumentation/core/build.gradle.kts" }}-{{ checksum "instrumentation/compose/build.gradle.kts" }}-{{ checksum "instrumentation/extensions/build.gradle.kts" }}-{{ checksum "instrumentation/runner/build.gradle.kts" }}-{{ checksum "instrumentation/sample/build.gradle.kts" }}-{{ checksum "instrumentation/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "build-logic/src/main/kotlin/Environment.kt" }}-{{ checksum "build-logic/src/main/kotlin/Dependencies.kt" }}
11+
key: jars-{{ checksum "build-logic/build.gradle.kts" }}-{{ checksum "plugin/build.gradle.kts" }}-{{ checksum "plugin/android-junit5/build.gradle.kts" }}-{{ checksum "plugin/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "instrumentation/build.gradle.kts" }}-{{ checksum "instrumentation/core/build.gradle.kts" }}-{{ checksum "instrumentation/compose/build.gradle.kts" }}-{{ checksum "instrumentation/extensions/build.gradle.kts" }}-{{ checksum "instrumentation/runner/build.gradle.kts" }}-{{ checksum "instrumentation/sample/build.gradle.kts" }}-{{ checksum "instrumentation/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "build-logic/src/main/kotlin/Environment.kt" }}-{{ checksum "build-logic/src/main/kotlin/Dependencies.kt" }}
1212

1313
commands:
1414
construct_signing_key:
@@ -24,14 +24,12 @@ jobs:
2424
- checkout
2525
- restore_cache:
2626
<<: *cache_key
27-
2827
- run:
2928
name: (Plugin) Build
3029
command: cd plugin && ./gradlew :android-junit5:assemble --stacktrace
3130
- run:
3231
name: (Plugin) Test
33-
command: cd plugin && ./gradlew :android-junit5:check --stacktrace
34-
32+
command: cd plugin && ./gradlew :build-logic:test :android-junit5:check --stacktrace
3533
- run:
3634
name: (Instrumentation) Download Dependencies
3735
command: cd instrumentation && ./gradlew androidDependencies
@@ -48,13 +46,11 @@ jobs:
4846
- run:
4947
name: (Instrumentation) Test
5048
command: cd instrumentation && ./gradlew :core:check :extensions:check :runner:check :compose:check --stacktrace
51-
5249
- save_cache:
5350
<<: *cache_key
5451
paths:
5552
- ~/.gradle/caches
5653
- ~/.gradle/wrapper
57-
5854
- run:
5955
name: Store Google Service Account
6056
command: echo $GCLOUD_SERVICE_KEY > ${HOME}/gcloud-service-key.json
@@ -63,7 +59,6 @@ jobs:
6359
command: |
6460
sudo gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json
6561
sudo gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
66-
6762
- run:
6863
name: Test with Firebase Test Lab
6964
command: >
@@ -82,7 +77,6 @@ jobs:
8277
command: |
8378
mkdir test-lab-results
8479
sudo gsutil -m cp -r -U `sudo gsutil ls gs://cloud-test-${GOOGLE_PROJECT_ID} | tail -1` test-lab-results/ | true
85-
8680
- persist_to_workspace:
8781
root: ~/root
8882
paths:
@@ -115,14 +109,14 @@ jobs:
115109
<<: *cache_key
116110
- construct_signing_key
117111
- run:
118-
name: (Plugin) Build & Deploy
112+
name: (Instrumentation) Build & Deploy
119113
command: |
120-
cd plugin
114+
cd instrumentation
121115
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --stacktrace
122116
- run:
123-
name: (Instrumentation) Build & Deploy
117+
name: (Plugin) Build & Deploy
124118
command: |
125-
cd instrumentation
119+
cd plugin
126120
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --stacktrace
127121
- store_artifacts:
128122
path: plugin/android-junit5/build/publications

build-logic/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
plugins {
22
`kotlin-dsl`
3+
java
34
}
45

56
repositories {
67
mavenCentral()
78
}
9+
10+
dependencies {
11+
implementation(gradleApi())
12+
testImplementation("junit:junit:+")
13+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ object Artifacts {
100100
object Instrumentation {
101101
const val groupId = "de.mannodermaus.junit5"
102102
private const val currentVersion = "1.5.1-SNAPSHOT"
103-
const val latestStableVersion = "1.5.0"
103+
private const val latestStableVersion = "1.5.0"
104104

105105
val Core = Deployed(
106106
platform = Android(minSdk = 19),

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fun Project.configureTestResources() {
3030

3131
"KOTLIN_VERSION" to libs.versions.kotlin,
3232
"JUNIT_JUPITER_VERSION" to libs.versions.junitJupiter,
33-
"JUNIT5_ANDROID_LIBS_VERSION" to Artifacts.Instrumentation.latestStableVersion,
33+
"JUNIT5_ANDROID_LIBS_VERSION" to Artifacts.Instrumentation.Core.latestStableVersion,
3434

3535
// Collect all supported AGP versions into a single string.
3636
// This string is delimited with semicolons, and each of the separated values itself is a 3-tuple.
@@ -134,6 +134,43 @@ fun Project.configureTestResources() {
134134
}
135135
}
136136

137+
fun findInstrumentationVersion(
138+
pluginVersion: String = Artifacts.Plugin.currentVersion,
139+
currentInstrumentationVersion: String = Artifacts.Instrumentation.Core.currentVersion,
140+
stableInstrumentationVersion: String = Artifacts.Instrumentation.Core.latestStableVersion
141+
): String {
142+
return when {
143+
pluginVersion.endsWith("-SNAPSHOT") -> currentInstrumentationVersion
144+
currentInstrumentationVersion.endsWith("-SNAPSHOT") -> stableInstrumentationVersion
145+
else -> currentInstrumentationVersion
146+
}
147+
}
148+
149+
fun Copy.configureCreateVersionClassTask(
150+
instrumentationVersion: String = findInstrumentationVersion(),
151+
fromPath: String = "src/main/templates/Libraries.kt",
152+
intoPath: String = "build/generated/sources/plugin/de/mannodermaus",
153+
) {
154+
from(fromPath)
155+
into(intoPath)
156+
filter(
157+
mapOf(
158+
"tokens" to mapOf(
159+
"INSTRUMENTATION_GROUP" to Artifacts.Instrumentation.groupId,
160+
"INSTRUMENTATION_COMPOSE" to Artifacts.Instrumentation.Compose.artifactId,
161+
"INSTRUMENTATION_CORE" to Artifacts.Instrumentation.Core.artifactId,
162+
"INSTRUMENTATION_EXTENSIONS" to Artifacts.Instrumentation.Extensions.artifactId,
163+
"INSTRUMENTATION_RUNNER" to Artifacts.Instrumentation.Runner.artifactId,
164+
165+
// Find an appropriate version of the instrumentation library,
166+
// depending on the version of how the plugin is configured
167+
"INSTRUMENTATION_VERSION" to instrumentationVersion,
168+
)
169+
), ReplaceTokens::class.java
170+
)
171+
outputs.upToDateWhen { false }
172+
}
173+
137174
/**
138175
* Helper Task class for generating an up-to-date version of the project's README.md.
139176
* Using a template file, the plugin's version constants & other dependency versions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import org.junit.Test;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
public class FindInstrumentationVersionTests {
6+
@Test
7+
public void findCorrectVersionForSnapshotPlugin() {
8+
String actual = TasksKt.findInstrumentationVersion(
9+
"plugin-1.0-SNAPSHOT",
10+
"instrumentation-2.0-SNAPSHOT",
11+
"instrumentation-1.0"
12+
);
13+
14+
assertEquals("instrumentation-2.0-SNAPSHOT", actual);
15+
}
16+
17+
@Test
18+
public void findCorrectVersionForStablePluginAndStableInstrumentation() {
19+
String actual = TasksKt.findInstrumentationVersion(
20+
"plugin-1.0",
21+
"instrumentation-2.0",
22+
"instrumentation-1.0"
23+
);
24+
25+
assertEquals("instrumentation-2.0", actual);
26+
}
27+
28+
@Test
29+
public void findCorrectVersionForStablePluginAndSnapshotInstrumentation() {
30+
String actual = TasksKt.findInstrumentationVersion(
31+
"plugin-1.0",
32+
"instrumentation-2.0-SNAPSHOT",
33+
"instrumentation-1.0"
34+
);
35+
36+
assertEquals("instrumentation-1.0", actual);
37+
}
38+
}

instrumentation/build.gradle.kts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,13 @@ plugins {
44
}
55

66
buildscript {
7-
repositories {
8-
google()
9-
mavenCentral()
10-
gradlePluginPortal()
11-
jitpack()
12-
}
13-
147
dependencies {
158
classpath(libs.plugins.kotlin)
169
classpath(libs.plugins.dokka)
1710
classpath(libs.plugins.android(SupportedAgp.newestStable))
1811
}
1912
}
2013

21-
allprojects {
22-
repositories {
23-
google()
24-
mavenCentral()
25-
sonatypeSnapshots()
26-
}
27-
}
28-
2914
apiValidation {
3015
ignoredPackages.add("de.mannodermaus.junit5.internal")
3116
ignoredPackages.add("de.mannodermaus.junit5.compose.internal")

instrumentation/sample/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id("com.android.application")
55
kotlin("android")
66
id("jacoco")
7-
id("de.mannodermaus.android-junit5").version(Artifacts.Plugin.latestStableVersion)
7+
id("de.mannodermaus.android-junit5").version(Artifacts.Plugin.currentVersion)
88
}
99

1010
val javaVersion = JavaVersion.VERSION_11
@@ -22,6 +22,9 @@ android {
2222

2323
// Make sure to use the AndroidJUnitRunner (or a sub-class) in order to hook in the JUnit 5 Test Builder
2424
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
25+
26+
// These two lines are not needed for a normal integration;
27+
// this sample project disables the automatic integration, so it must be done manually
2528
testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
2629
testInstrumentationRunnerArguments["configurationParameters"] = "junit.jupiter.execution.parallel.enabled=true,junit.jupiter.execution.parallel.mode.default=concurrent"
2730

instrumentation/settings.gradle.kts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
@file:Suppress("UnstableApiUsage")
2+
13
rootProject.name = "android-junit5-instrumentation"
4+
25
includeBuild("../build-logic")
36
include(":core")
47
include(":compose")
@@ -7,3 +10,29 @@ include(":runner")
710
include(":sample")
811
include(":testutil")
912
include(":testutil-reflect")
13+
14+
pluginManagement {
15+
repositories {
16+
google()
17+
mavenCentral()
18+
gradlePluginPortal()
19+
maven {
20+
setUrl("https://jitpack.io")
21+
}
22+
maven {
23+
setUrl("https://oss.sonatype.org/content/repositories/snapshots")
24+
mavenContent { snapshotsOnly() }
25+
}
26+
}
27+
}
28+
29+
dependencyResolutionManagement {
30+
repositories {
31+
google()
32+
mavenCentral()
33+
maven {
34+
setUrl("https://oss.sonatype.org/content/repositories/snapshots")
35+
mavenContent { snapshotsOnly() }
36+
}
37+
}
38+
}

plugin/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Change Log
66
- Updates to the `jacocoOptions` DSL
77
- Change the return type of each report type to match Jacoco expectations (html -> Directory; csv & xml -> File)
88
- Turn off generation of csv & xml reports by default, matching Jacoco default configuration
9+
- Fix: Use the correct version of the instrumentation libraries with the plugin (#345)
910

1011
## 1.10.2.0 (2024-07-25)
1112
- JUnit 5.10.2

plugin/android-junit5/build.gradle.kts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import org.apache.tools.ant.filters.ReplaceTokens
2-
import org.gradle.api.internal.classpath.ModuleRegistry
31
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
42
import org.gradle.api.tasks.testing.logging.TestLogEvent
5-
import org.gradle.kotlin.dsl.support.serviceOf
63
import org.jetbrains.dokka.gradle.DokkaTask
74
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
85

@@ -81,23 +78,10 @@ project.configureTestResources()
8178

8279
// Generate a file with the latest versions of the plugin & instrumentation
8380
val genFolder = "build/generated/sources/plugin"
84-
val versionClassTask = tasks.register<Copy>("createVersionClass") {
85-
from("src/main/templates/Libraries.kt")
86-
into("$genFolder/de/mannodermaus")
87-
filter(
88-
mapOf(
89-
"tokens" to mapOf(
90-
"INSTRUMENTATION_GROUP" to Artifacts.Instrumentation.groupId,
91-
"INSTRUMENTATION_COMPOSE" to Artifacts.Instrumentation.Compose.artifactId,
92-
"INSTRUMENTATION_CORE" to Artifacts.Instrumentation.Core.artifactId,
93-
"INSTRUMENTATION_EXTENSIONS" to Artifacts.Instrumentation.Extensions.artifactId,
94-
"INSTRUMENTATION_RUNNER" to Artifacts.Instrumentation.Runner.artifactId,
95-
"INSTRUMENTATION_VERSION" to Artifacts.Instrumentation.latestStableVersion,
96-
)
97-
), ReplaceTokens::class.java
98-
)
99-
outputs.upToDateWhen { false }
100-
}
81+
val versionClassTask = tasks.register<Copy>(
82+
"createVersionClass",
83+
Copy::configureCreateVersionClassTask,
84+
)
10185
sourceSets {
10286
main {
10387
kotlin.srcDir(genFolder)

0 commit comments

Comments
 (0)