Skip to content

Commit

Permalink
Use correct bundled version of instrumentation libraries for the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mannodermaus committed Aug 1, 2024
1 parent c7513d2 commit ec19040
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 50 deletions.
18 changes: 6 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defaults: &defaults
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

cache_key: &cache_key
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" }}
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" }}

commands:
construct_signing_key:
Expand All @@ -24,14 +24,12 @@ jobs:
- checkout
- restore_cache:
<<: *cache_key

- run:
name: (Plugin) Build
command: cd plugin && ./gradlew :android-junit5:assemble --stacktrace
- run:
name: (Plugin) Test
command: cd plugin && ./gradlew :android-junit5:check --stacktrace

command: cd plugin && ./gradlew :build-logic:test :android-junit5:check --stacktrace
- run:
name: (Instrumentation) Download Dependencies
command: cd instrumentation && ./gradlew androidDependencies
Expand All @@ -48,13 +46,11 @@ jobs:
- run:
name: (Instrumentation) Test
command: cd instrumentation && ./gradlew :core:check :extensions:check :runner:check :compose:check --stacktrace

- save_cache:
<<: *cache_key
paths:
- ~/.gradle/caches
- ~/.gradle/wrapper

- run:
name: Store Google Service Account
command: echo $GCLOUD_SERVICE_KEY > ${HOME}/gcloud-service-key.json
Expand All @@ -63,7 +59,6 @@ jobs:
command: |
sudo gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json
sudo gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
- run:
name: Test with Firebase Test Lab
command: >
Expand All @@ -82,7 +77,6 @@ jobs:
command: |
mkdir test-lab-results
sudo gsutil -m cp -r -U `sudo gsutil ls gs://cloud-test-${GOOGLE_PROJECT_ID} | tail -1` test-lab-results/ | true
- persist_to_workspace:
root: ~/root
paths:
Expand Down Expand Up @@ -115,14 +109,14 @@ jobs:
<<: *cache_key
- construct_signing_key
- run:
name: (Plugin) Build & Deploy
name: (Instrumentation) Build & Deploy
command: |
cd plugin
cd instrumentation
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --stacktrace
- run:
name: (Instrumentation) Build & Deploy
name: (Plugin) Build & Deploy
command: |
cd instrumentation
cd plugin
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --stacktrace
- store_artifacts:
path: plugin/android-junit5/build/publications
Expand Down
6 changes: 6 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
plugins {
`kotlin-dsl`
java
}

repositories {
mavenCentral()
}

dependencies {
implementation(gradleApi())
testImplementation("junit:junit:+")
}
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ object Artifacts {
object Instrumentation {
const val groupId = "de.mannodermaus.junit5"
private const val currentVersion = "1.5.1-SNAPSHOT"
const val latestStableVersion = "1.5.0"
private const val latestStableVersion = "1.5.0"

val Core = Deployed(
platform = Android(minSdk = 19),
Expand Down
39 changes: 38 additions & 1 deletion build-logic/src/main/kotlin/Tasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun Project.configureTestResources() {

"KOTLIN_VERSION" to libs.versions.kotlin,
"JUNIT_JUPITER_VERSION" to libs.versions.junitJupiter,
"JUNIT5_ANDROID_LIBS_VERSION" to Artifacts.Instrumentation.latestStableVersion,
"JUNIT5_ANDROID_LIBS_VERSION" to Artifacts.Instrumentation.Core.latestStableVersion,

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

fun findInstrumentationVersion(
pluginVersion: String = Artifacts.Plugin.currentVersion,
currentInstrumentationVersion: String = Artifacts.Instrumentation.Core.currentVersion,
stableInstrumentationVersion: String = Artifacts.Instrumentation.Core.latestStableVersion
): String {
return when {
pluginVersion.endsWith("-SNAPSHOT") -> currentInstrumentationVersion
currentInstrumentationVersion.endsWith("-SNAPSHOT") -> stableInstrumentationVersion
else -> currentInstrumentationVersion
}
}

fun Copy.configureCreateVersionClassTask(
instrumentationVersion: String = findInstrumentationVersion(),
fromPath: String = "src/main/templates/Libraries.kt",
intoPath: String = "build/generated/sources/plugin/de/mannodermaus",
) {
from(fromPath)
into(intoPath)
filter(
mapOf(
"tokens" to mapOf(
"INSTRUMENTATION_GROUP" to Artifacts.Instrumentation.groupId,
"INSTRUMENTATION_COMPOSE" to Artifacts.Instrumentation.Compose.artifactId,
"INSTRUMENTATION_CORE" to Artifacts.Instrumentation.Core.artifactId,
"INSTRUMENTATION_EXTENSIONS" to Artifacts.Instrumentation.Extensions.artifactId,
"INSTRUMENTATION_RUNNER" to Artifacts.Instrumentation.Runner.artifactId,

// Find an appropriate version of the instrumentation library,
// depending on the version of how the plugin is configured
"INSTRUMENTATION_VERSION" to instrumentationVersion,
)
), ReplaceTokens::class.java
)
outputs.upToDateWhen { false }
}

/**
* Helper Task class for generating an up-to-date version of the project's README.md.
* Using a template file, the plugin's version constants & other dependency versions
Expand Down
38 changes: 38 additions & 0 deletions build-logic/src/test/java/FindInstrumentationVersionTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class FindInstrumentationVersionTests {
@Test
public void findCorrectVersionForSnapshotPlugin() {
String actual = TasksKt.findInstrumentationVersion(
"plugin-1.0-SNAPSHOT",
"instrumentation-2.0-SNAPSHOT",
"instrumentation-1.0"
);

assertEquals("instrumentation-2.0-SNAPSHOT", actual);
}

@Test
public void findCorrectVersionForStablePluginAndStableInstrumentation() {
String actual = TasksKt.findInstrumentationVersion(
"plugin-1.0",
"instrumentation-2.0",
"instrumentation-1.0"
);

assertEquals("instrumentation-2.0", actual);
}

@Test
public void findCorrectVersionForStablePluginAndSnapshotInstrumentation() {
String actual = TasksKt.findInstrumentationVersion(
"plugin-1.0",
"instrumentation-2.0-SNAPSHOT",
"instrumentation-1.0"
);

assertEquals("instrumentation-1.0", actual);
}
}
15 changes: 0 additions & 15 deletions instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,13 @@ plugins {
}

buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
jitpack()
}

dependencies {
classpath(libs.plugins.kotlin)
classpath(libs.plugins.dokka)
classpath(libs.plugins.android(SupportedAgp.newestStable))
}
}

allprojects {
repositories {
google()
mavenCentral()
sonatypeSnapshots()
}
}

apiValidation {
ignoredPackages.add("de.mannodermaus.junit5.internal")
ignoredPackages.add("de.mannodermaus.junit5.compose.internal")
Expand Down
5 changes: 4 additions & 1 deletion instrumentation/sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id("com.android.application")
kotlin("android")
id("jacoco")
id("de.mannodermaus.android-junit5").version(Artifacts.Plugin.latestStableVersion)
id("de.mannodermaus.android-junit5").version(Artifacts.Plugin.currentVersion)
}

val javaVersion = JavaVersion.VERSION_11
Expand All @@ -22,6 +22,9 @@ android {

// Make sure to use the AndroidJUnitRunner (or a sub-class) in order to hook in the JUnit 5 Test Builder
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

// These two lines are not needed for a normal integration;
// this sample project disables the automatic integration, so it must be done manually
testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
testInstrumentationRunnerArguments["configurationParameters"] = "junit.jupiter.execution.parallel.enabled=true,junit.jupiter.execution.parallel.mode.default=concurrent"

Expand Down
29 changes: 29 additions & 0 deletions instrumentation/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@file:Suppress("UnstableApiUsage")

rootProject.name = "android-junit5-instrumentation"

includeBuild("../build-logic")
include(":core")
include(":compose")
Expand All @@ -7,3 +10,29 @@ include(":runner")
include(":sample")
include(":testutil")
include(":testutil-reflect")

pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven {
setUrl("https://jitpack.io")
}
maven {
setUrl("https://oss.sonatype.org/content/repositories/snapshots")
mavenContent { snapshotsOnly() }
}
}
}

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
setUrl("https://oss.sonatype.org/content/repositories/snapshots")
mavenContent { snapshotsOnly() }
}
}
}
1 change: 1 addition & 0 deletions plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Change Log

## Unreleased
- JUnit 5.10.3
- Fix: Use the correct version of the instrumentation libraries with the plugin (#345)

## 1.10.2.0 (2024-07-25)
- JUnit 5.10.2
Expand Down
24 changes: 4 additions & 20 deletions plugin/android-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.internal.classpath.ModuleRegistry
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.kotlin.dsl.support.serviceOf
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand Down Expand Up @@ -81,23 +78,10 @@ project.configureTestResources()

// Generate a file with the latest versions of the plugin & instrumentation
val genFolder = "build/generated/sources/plugin"
val versionClassTask = tasks.register<Copy>("createVersionClass") {
from("src/main/templates/Libraries.kt")
into("$genFolder/de/mannodermaus")
filter(
mapOf(
"tokens" to mapOf(
"INSTRUMENTATION_GROUP" to Artifacts.Instrumentation.groupId,
"INSTRUMENTATION_COMPOSE" to Artifacts.Instrumentation.Compose.artifactId,
"INSTRUMENTATION_CORE" to Artifacts.Instrumentation.Core.artifactId,
"INSTRUMENTATION_EXTENSIONS" to Artifacts.Instrumentation.Extensions.artifactId,
"INSTRUMENTATION_RUNNER" to Artifacts.Instrumentation.Runner.artifactId,
"INSTRUMENTATION_VERSION" to Artifacts.Instrumentation.latestStableVersion,
)
), ReplaceTokens::class.java
)
outputs.upToDateWhen { false }
}
val versionClassTask = tasks.register<Copy>(
"createVersionClass",
Copy::configureCreateVersionClassTask,
)
sourceSets {
main {
kotlin.srcDir(genFolder)
Expand Down

0 comments on commit ec19040

Please sign in to comment.