From 6f202a964e216405598a0309413010cedb1c3816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Old=C5=99ich=20Jedli=C4=8Dka?= Date: Wed, 19 Nov 2025 17:47:29 +0100 Subject: [PATCH] Allow partly parallel Maven execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This partly fixes Maven execution in parallel forks, because it postpones evaluating of the rootFolder (`user.dir` value) until it is really needed during execution. Without the fix the path could be evaluated in the main process, meaning the `user.dir` is not set correctly to the tested module. It still does not allow reusing of the forks (reuseForks parameter in maven-surefire-plugin and maven-failsafe-plugin), but at least allows parallel execution (forkCount greater than 1). When reusing the forks, the SnapshotSystemJUnit5.finishedAllTests() complains that it was called more than once, so the reuseForks has to be disabled (set to false). This partly fixes #551. Signed-off-by: Oldřich Jedlička --- jvm/CHANGELOG.md | 1 + .../selfie/junit5/SnapshotFileLayoutJUnit5.kt | 11 +++++++---- .../selfie/kotest/SnapshotFileLayoutKotest.kt | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/jvm/CHANGELOG.md b/jvm/CHANGELOG.md index 16579724..7aaba6a8 100644 --- a/jvm/CHANGELOG.md +++ b/jvm/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - Unsupported test sources (such as `FieldSource`) no longer cause the JUnit5 runner to crash. ([#550](https://github.com/diffplug/selfie/pull/550) fixes [#549](https://github.com/diffplug/selfie/issues/549)) +- Partly allow parallel Maven execution with surefire and failsafe plugins with `forkCount` greater than one by making evaluation of few properties lazy. This postpones evaluation into the forks. Still, due to internal Selfie state tracking, this needs to be run with `reuseForks` set to `false`. ([#557](https://github.com/diffplug/selfie/pull/557) partly fixes [#551](https://github.com/diffplug/selfie/issues/551)) ### Changed - Bump minimum required Kotest from `5.4.0` to `5.6.0` ([#535](https://github.com/diffplug/selfie/pull/535)) - required to fix `java.lang.NoSuchMethodError: 'long kotlin.time.Duration$Companion.milliseconds-UwyO8pc(long)'` diff --git a/jvm/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/SnapshotFileLayoutJUnit5.kt b/jvm/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/SnapshotFileLayoutJUnit5.kt index 6c8590bc..e620fcdf 100644 --- a/jvm/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/SnapshotFileLayoutJUnit5.kt +++ b/jvm/selfie-runner-junit5/src/main/kotlin/com/diffplug/selfie/junit5/SnapshotFileLayoutJUnit5.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 DiffPlug + * Copyright (C) 2023-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,13 +27,16 @@ class SnapshotFileLayoutJUnit5(settings: SelfieSettingsAPI, override val fs: FS) internal val smuggledError = AtomicReference( if (settings is SelfieSettingsSmuggleError) settings.error else null) - override val rootFolder = TypedPath.ofFolder(settings.rootFolder.absolutePath) - private val otherSourceRoots = settings.otherSourceRoots + internal val settings = settings + override val rootFolder: TypedPath by lazy { + TypedPath.ofFolder(settings.rootFolder.absolutePath) + } + private val otherSourceRoots: List by lazy { settings.otherSourceRoots } override val allowMultipleEquivalentWritesToOneLocation = settings.allowMultipleEquivalentWritesToOneLocation override val javaDontUseTripleQuoteLiterals = settings.javaDontUseTripleQuoteLiterals val snapshotFolderName = settings.snapshotFolderName - internal val unixNewlines = inferDefaultLineEndingIsUnix(rootFolder, fs) + internal val unixNewlines: Boolean by lazy { inferDefaultLineEndingIsUnix(rootFolder, fs) } val extension: String = ".ss" private val cache = SourcePathCache(this::computePathForCall, Runtime.getRuntime().availableProcessors() * 4) diff --git a/jvm/selfie-runner-kotest/src/commonMain/kotlin/com/diffplug/selfie/kotest/SnapshotFileLayoutKotest.kt b/jvm/selfie-runner-kotest/src/commonMain/kotlin/com/diffplug/selfie/kotest/SnapshotFileLayoutKotest.kt index e6be8754..8e532826 100644 --- a/jvm/selfie-runner-kotest/src/commonMain/kotlin/com/diffplug/selfie/kotest/SnapshotFileLayoutKotest.kt +++ b/jvm/selfie-runner-kotest/src/commonMain/kotlin/com/diffplug/selfie/kotest/SnapshotFileLayoutKotest.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 DiffPlug + * Copyright (C) 2024-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.