diff --git a/idea/src/mill/idea/GenIdeaImpl.scala b/idea/src/mill/idea/GenIdeaImpl.scala
index 14d6094d123..7d9d891a556 100755
--- a/idea/src/mill/idea/GenIdeaImpl.scala
+++ b/idea/src/mill/idea/GenIdeaImpl.scala
@@ -786,6 +786,11 @@ case class GenIdeaImpl(
}
+
+ /**
+ * @param libNames The library dependencies (external dependencies)
+ * @param depNames The dependency modules (internal dependencies)
+ */
def moduleXmlTemplate(
basePath: os.Path,
scalaVersionOpt: Option[String],
@@ -871,14 +876,6 @@ case class GenIdeaImpl(
- {
- for (dep <- depNames.sorted)
- yield dep.scope match {
- case None =>
- case Some(scope) =>
-
- }
- }
{
for (name <- libNames.sorted)
yield name.scope match {
@@ -886,7 +883,17 @@ case class GenIdeaImpl(
case Some(scope) =>
}
-
+ }
+ {
+ // we place the module dependencies after the library dependencies, as IJ is leaking the (transitive)
+ // library dependencies of the module dependencies, even if they are not exported.
+ // This can result in wrong classpath when lib dependencies are refined.
+ for (dep <- depNames.sorted)
+ yield dep.scope match {
+ case None =>
+ case Some(scope) =>
+
+ }
}
{
diff --git a/integration/feature/gen-idea/repo/extended/idea/mill_modules/helloworld.test.iml b/integration/feature/gen-idea/repo/extended/idea/mill_modules/helloworld.test.iml
index bc388953e1e..9320333ee26 100644
--- a/integration/feature/gen-idea/repo/extended/idea/mill_modules/helloworld.test.iml
+++ b/integration/feature/gen-idea/repo/extended/idea/mill_modules/helloworld.test.iml
@@ -8,7 +8,7 @@
-
+
diff --git a/integration/feature/gen-idea/repo/hello-world/idea/mill_modules/helloworld.test.iml b/integration/feature/gen-idea/repo/hello-world/idea/mill_modules/helloworld.test.iml
index 708183f9e8a..ee320609f2f 100644
--- a/integration/feature/gen-idea/repo/hello-world/idea/mill_modules/helloworld.test.iml
+++ b/integration/feature/gen-idea/repo/hello-world/idea/mill_modules/helloworld.test.iml
@@ -8,11 +8,11 @@
-
+