diff --git a/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 04526b24b..66cc5f8e8 100644 --- a/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -77,7 +77,7 @@ class ApplicationTest : BasePluginTest() { val zip = path("build/distributions/myapp-shadow-1.0.zip") assertThat(zip).exists() - val entries = ZipFile(zip.toFile()).entries.toList().map { it.name } + val entries = ZipFile(zip.toFile()).use { it.entries }.toList().map { it.name } assertThat(entries).containsAtLeast( "myapp-shadow-1.0/lib/myapp-1.0-all.jar", "myapp-shadow-1.0/lib/a-1.0.jar", diff --git a/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt b/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt index f1bcaa73c..98aefc49e 100644 --- a/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt +++ b/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt @@ -36,9 +36,11 @@ import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.TestInstance +import org.junit.jupiter.api.io.TempDir @TestInstance(TestInstance.Lifecycle.PER_CLASS) abstract class BasePluginTest { + @TempDir lateinit var projectRoot: Path lateinit var localRepo: AppendableMavenRepository @@ -64,20 +66,12 @@ abstract class BasePluginTest { @BeforeEach open fun setup() { - projectRoot = createTempDirectory() - projectScriptPath.writeText(getDefaultProjectBuildScript(withGroup = true, withVersion = true)) settingsScriptPath.writeText(getDefaultSettingsBuildScript()) } - @ExperimentalPathApi @AfterEach fun cleanup() { - runCatching { - // TODO: workaround for https://github.com/junit-team/junit5/issues/2811. - projectRoot.deleteRecursively() - } - println(projectScriptPath.readText()) } diff --git a/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt b/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt index b57ba14ad..6c546609f 100644 --- a/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt +++ b/src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt @@ -210,16 +210,17 @@ class RelocationTest : BasePluginTest() { ) } - val classLoader = URLClassLoader( + URLClassLoader( arrayOf(outputShadowJar.toUri().toURL()), ClassLoader.getSystemClassLoader().parent, - ) - assertFailure { - // check that the class can be loaded. If the file was not relocated properly, we should get a NoDefClassFound - // Isolated class loader with only the JVM system jars and the output jar from the test project - classLoader.loadClass("shadow.ShadowTest") - fail("Should not reach here.") - }.isInstanceOf(AssertionFailedError::class) + ).use { classLoader -> + assertFailure { + // check that the class can be loaded. If the file was not relocated properly, we should get a NoDefClassFound + // Isolated class loader with only the JVM system jars and the output jar from the test project + classLoader.loadClass("shadow.ShadowTest") + fail("Should not reach here.") + }.isInstanceOf(AssertionFailedError::class) + } } @Test