From 0c7505b744065effca8d949fdf0bf0c7f27bf50e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 10 Dec 2019 22:49:17 +0100 Subject: [PATCH] junit 5: keep downloaded dependencies at the classpath start to avoid jar hell (IDEA-228358) GitOrigin-RevId: 195ad9058566479639a5f2ef3a9c2ab1a10b641f --- .../intellij/execution/junit/TestObject.java | 24 ++++++++++++------- .../junit4/JUnit5IntegrationTest.java | 2 ++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit/TestObject.java b/plugins/junit/src/com/intellij/execution/junit/TestObject.java index e474ccaa8b7e..6c679a97e038 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestObject.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestObject.java @@ -306,9 +306,9 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState additionalDependencies = new ArrayList<>(); if (!hasPackageWithDirectories(psiFacade, "org.junit.platform.launcher", globalSearchScope)) { - downloadDependenciesWhenRequired(project, pathsList, + downloadDependenciesWhenRequired(project, additionalDependencies, new RepositoryLibraryProperties("org.junit.platform", "junit-platform-launcher", launcherVersion)); } @@ -320,7 +320,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState= 0 ? jupiterVersion : "4.12." + StringUtil.getShortName(launcherVersion); - downloadDependenciesWhenRequired(project, pathsList, + downloadDependenciesWhenRequired(project, additionalDependencies, new RepositoryLibraryProperties("org.junit.vintage", "junit-vintage-engine", version)); } } + + //add downloaded dependencies before everything else to avoid dependencies conflicts on org.junit.platform.common e.g. with spring boot test + final PathsList targetList = isModularized ? javaParameters.getModulePath() : javaParameters.getClassPath(); + for (int i = additionalDependencies.size() - 1; i >= 0; i--) { + targetList.addFirst(additionalDependencies.get(i)); + } } public static boolean hasJUnit5EnginesAPI(GlobalSearchScope globalSearchScope, JavaPsiFacade psiFacade) { @@ -370,7 +376,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState classPath, RepositoryLibraryProperties properties) throws CantRunException { Collection roots = JarRepositoryManager.loadDependenciesModal(project, properties, false, false, null, null); if (roots.isEmpty()) { @@ -378,9 +384,9 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState ignoredTests = processOutput.messages.stream() .filter(TestIgnored.class::isInstance)