Skip to content

Commit ce60bab

Browse files
authored
Using local cache for tests (#338)
1 parent 0c126d8 commit ce60bab

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ mavenPublishing {
104104
}
105105

106106
tasks.test {
107-
environment("TEMP_DIR" to temporaryDir)
107+
environment("TEMP_DIR", temporaryDir.toRelativeString(projectDir))
108108
useJUnitPlatform()
109109
javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(17) } // required by AGP
110110
finalizedBy(tasks.jacocoTestReport)

plugin/src/test/kotlin/com/github/gmazzo/buildconfig/BuildConfigPluginBaseTest.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import org.junit.jupiter.params.provider.MethodSource
1616
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1717
abstract class BuildConfigPluginBaseTest(private val isKMP: Boolean = false) {
1818

19-
private val baseDir = File(System.getenv("TEMP_DIR"), javaClass.simpleName)
19+
private val baseDir = File(
20+
System.getenv("TEMP_DIR"),
21+
javaClass.simpleName
22+
).absoluteFile
23+
2024
protected val gradleMin = BuildConfigPlugin.MIN_GRADLE_VERSION
2125
protected val gradleLatest: String = GradleVersion.current().baseVersion.version
2226
protected val kotlinMin = "1.9.+"
@@ -58,7 +62,7 @@ abstract class BuildConfigPluginBaseTest(private val isKMP: Boolean = false) {
5862
.withProjectDir(projectDir)
5963
.withTestKitDir(projectDir.resolve(".testkit"))
6064
.withGradleVersion(gradleVersion)
61-
.withArguments("build", "-s")
65+
.withArguments("build", "-s", "--build-cache")
6266
.build()
6367
}
6468

@@ -72,6 +76,10 @@ abstract class BuildConfigPluginBaseTest(private val isKMP: Boolean = false) {
7276
if (androidVersion != null) synchronized(BuildConfigPluginBaseTest, block) else block()
7377

7478
private fun Args.writeBuildGradle() {
79+
val userBuildCacheDir = File(System.getProperty("user.home"))
80+
.resolve(".gradle/caches/build-cache-1")
81+
.takeIf { it.isDirectory }
82+
7583
projectDir.resolve("settings.gradle.kts").writeText(
7684
"""
7785
pluginManagement {
@@ -85,6 +93,8 @@ abstract class BuildConfigPluginBaseTest(private val isKMP: Boolean = false) {
8593
id("jacoco-testkit-coverage")
8694
}
8795
96+
${ if (userBuildCacheDir != null) "buildCache.local.directory = file(\"$userBuildCacheDir\")" else "" }
97+
8898
rootProject.name = "$PROJECT_NAME"
8999
""".trimIndent()
90100
)
@@ -193,7 +203,7 @@ abstract class BuildConfigPluginBaseTest(private val isKMP: Boolean = false) {
193203
val withPackage: Boolean = true,
194204
) {
195205

196-
val projectDir = baseDir
206+
val projectDir: File = baseDir
197207
.resolve("gradle-$gradleVersion")
198208
.resolve("kotlin-${kotlinVersion ?: "none"}")
199209
.resolve("android-${androidVersion ?: "none"}")

plugin/src/test/kotlin/com/github/gmazzo/buildconfig/BuildConfigTaskCacheabilityTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import org.junit.jupiter.api.parallel.ExecutionMode
1515
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
1616
class BuildConfigTaskCacheabilityTest {
1717

18-
private val projectDir = File(System.getenv("TEMP_DIR"), BuildConfigTaskCacheabilityTest::class.simpleName!!)
18+
private val projectDir = File(
19+
System.getenv("TEMP_DIR"),
20+
BuildConfigTaskCacheabilityTest::class.simpleName!!
21+
).absoluteFile
1922

2023
private val buildScript = File(projectDir, "build.gradle.kts")
2124

0 commit comments

Comments
 (0)