Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transitiveCompileClasspath and bspTransitiveCompileClasspath out of sync #3013

Closed
patrick-schultz opened this issue Feb 15, 2024 · 3 comments · Fixed by #3017
Closed

transitiveCompileClasspath and bspTransitiveCompileClasspath out of sync #3013

patrick-schultz opened this issue Feb 15, 2024 · 3 comments · Fixed by #3017
Milestone

Comments

@patrick-schultz
Copy link

It seems that in the update from 0.11.6 to 0.11.7, the transitiveCompileClasspath and bspTransitiveCompileClasspath targets have diverged. transitiveCompileClasspath is the same, but bspTransitiveCompileClasspath is now pulling in many more dependencies, leading to conflicting versions of dependencies on the classpath.

I can resolve this issue by changing

  def bspTransitiveCompileClasspath: T[Agg[UnresolvedPath]] = T {
    T.traverse(transitiveModuleCompileModuleDeps)(m =>
      T.task {
        m.bspCompileClasspath() ++ Agg(m.bspCompileClassesPath())
      }
    )()
      .flatten
  }

to

  override def bspTransitiveCompileClasspath: T[Agg[UnresolvedPath]] = T {
    T.traverse(transitiveModuleCompileModuleDeps)(m =>
      T.task {
        m.localCompileClasspath().map(p => UnresolvedPath.ResolvedPath(p.path)) ++
          Agg(m.bspCompileClassesPath())
      }
    )()
      .flatten
  }

but I don't know if this is the proper fix.

For reference, note that transitiveCompileClasspath is defined

  def transitiveCompileClasspath: T[Agg[PathRef]] = T {
    T.traverse(transitiveModuleCompileModuleDeps)(m =>
      T.task { m.localCompileClasspath() ++ Agg(m.compile().classes) }
    )().flatten
  }
@lefou
Copy link
Member

lefou commented Feb 15, 2024

Do you have a reproducer that shows the mismatching products of these two targets?

@patrick-schultz
Copy link
Author

Sure, here's a small reproducer:

// build.sc
object foo extends ScalaModule {
  def scalaVersion = "2.12.15"
  override def moduleDeps = Seq(bar)
  override def ivyDeps = Agg(ivy"com.lihaoyi::mainargs:0.4.0")
}

object bar extends ScalaModule {
  def scalaVersion = "2.12.15"
  override def ivyDeps = Agg(ivy"com.lihaoyi::scalatags:0.8.2")
}
$ mill show foo.transitiveCompileClasspath
[1/1] show > [33/36] bar.zincReportCachedProblems
[
  "ref:v0:c984eca8:/Users/pschulz/dev/mill-playground/bar/compile-resources",
  "ref:v0:fdbc9b0a:/Users/pschulz/dev/mill-playground/out/bar/compile.dest/classes"
]

$ mill show foo.bspTransitiveCompileClasspath
[1/1] show > [2/18] bar.compileResources
[
  {
    "$type": "mill.scalalib.UnresolvedPath.ResolvedPath",
    "path": "/Users/pschulz/dev/mill-playground/bar/compile-resources"
  },
  {
    "$type": "mill.scalalib.UnresolvedPath.ResolvedPath",
    "path": "/Users/pschulz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/scalatags_2.12/0.8.2/scalatags_2.12-0.8.2.jar"
  },
  {
    "$type": "mill.scalalib.UnresolvedPath.ResolvedPath",
    "path": "/Users/pschulz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.15/scala-library-2.12.15.jar"
  },
  {
    "$type": "mill.scalalib.UnresolvedPath.ResolvedPath",
    "path": "/Users/pschulz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.12/0.1.7/sourcecode_2.12-0.1.7.jar"
  },
  {
    "$type": "mill.scalalib.UnresolvedPath.ResolvedPath",
    "path": "/Users/pschulz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/geny_2.12/0.2.0/geny_2.12-0.2.0.jar"
  },
  {
    "$type": "mill.scalalib.UnresolvedPath.DestPath",
    "subPath": "classes",
    "segments": [
      "bar",
      "compile"
    ]
  }
]

Actually, this is using mill 0.11.6. I must have been mistaken that this only appeared when I upgraded.

@patrick-schultz patrick-schultz changed the title transitiveCompileClasspath and bspTransitiveCompileClasspath out of sync in 0.11.7 transitiveCompileClasspath and bspTransitiveCompileClasspath out of sync Feb 15, 2024
@lefou
Copy link
Member

lefou commented Feb 15, 2024

Thank you. It's probably since Mill 0.11.3 and was most likely introduced in this PR #2735. I already had some suspicions back then.

lefou added a commit that referenced this issue Feb 18, 2024
Resolve some inconsistencies between the BSP and non-BSP versions of `compileClasspath` and `transitiveCompileClasspath`.

The `bspTransitiveCompileClasspath` contained resolve ivy dependencies, which resulted in to many and potentially conflicing jars ending up in the classpath.

Fix #3013
@lefou lefou added this to the 0.11.8 milestone Feb 18, 2024
lefou added a commit that referenced this issue Feb 18, 2024
Resolve some inconsistencies between the BSP and non-BSP versions of
`compileClasspath` and `transitiveCompileClasspath`.

The `bspTransitiveCompileClasspath` contained resolved ivy dependencies,
which resulted in too many and potentially conflicting jars ending up in
the same classpath.

Fix #3013

Pull request: #3017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants