diff --git a/cli/src/main/scala-2.11/coursier/cli/Coursier.scala b/cli/src/main/scala-2.11/coursier/cli/Coursier.scala index 5b3183b8f..6f9eaec65 100644 --- a/cli/src/main/scala-2.11/coursier/cli/Coursier.scala +++ b/cli/src/main/scala-2.11/coursier/cli/Coursier.scala @@ -13,6 +13,7 @@ import coursier.util.Parse import scala.annotation.tailrec import scala.language.reflectiveCalls +import scala.util.Try case class CommonOptions( @Help("Keep optional dependencies (Maven)") @@ -228,18 +229,23 @@ case class Launch( val contextLoader = Thread.currentThread().getContextClassLoader - val parentLoader0: ClassLoader = Launch.mainClassLoader(contextLoader) - .flatMap(cl => Option(cl.getParent)) - .getOrElse { - if (common.verbose0 >= 0) - Console.err.println( - "Warning: cannot find the main ClassLoader that launched coursier. " + - "Was coursier launched by its main launcher? " + - "The ClassLoader of the application that is about to be launched will be intertwined " + - "with the one of coursier, which may be a problem if their dependencies conflict." - ) + val parentLoader0: ClassLoader = + if (Try(contextLoader.loadClass("coursier.Launch")).isSuccess) + Launch.mainClassLoader(contextLoader) + .flatMap(cl => Option(cl.getParent)) + .getOrElse { + if (common.verbose0 >= 0) + Console.err.println( + "Warning: cannot find the main ClassLoader that launched coursier. " + + "Was coursier launched by its main launcher? " + + "The ClassLoader of the application that is about to be launched will be intertwined " + + "with the one of coursier, which may be a problem if their dependencies conflict." + ) + contextLoader + } + else + // proguarded -> no risk of conflicts, no need to find a specific ClassLoader contextLoader - } val (parentLoader, filteredFiles) = if (isolated.isolated.isEmpty)