-
Notifications
You must be signed in to change notification settings - Fork 928
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
0.13.12 regression in resolving org.scala-lang:scala-library in custom configuration #2786
Comments
How about with 0.13.13-RC3? |
Good question. Unfortunately, I get the same error:
|
@milessabin Could this be related to the mediator? |
Yes, it could, but so far I've not been persuaded that what's being attempted makes any sort of sense at all ... in what circumstances is it reasonable to want more than one version of scala-library on the classpath? |
To my best understanding, the classpaths are isolated between different configurations so there will only be one version of scala-library. Here's what the SBT documentation says about configurations:
It may very well be that I'm using configurations for the wrong purpose. All I want is a place to put together dependencies so I can classload scalafmt with scala-library 2.11.8. I am open for any suggestions on how to accomplish that. PS. The classpath in https://github.com/olafurpg/scalafmt/pull/522 (where I used org.typelevel:scala-library) contained two versions of scala-library. I agree that is a terrible idea. I closed the PR. |
More users have reported this issue. My current recommendation to them is to downgrade to 0.13.11, which I think is a shame. Is there a chance this might get fixed in 0.13.13? I would be happy with the ability to force a scala-library version in a specific scope: libraryDependencies += "org.scala-lang" % "scala-library" % "2.11.8" % "scalafmt" force() Alternatively, is there another way to call 2.11 libraries in SBT plugins? |
I'd like to help, but I have no idea what the implications of calling 2.11 libraries in SBT plugins are. All my experience with Scala over the last decade tells me that mixing Scala versions in a single JVM can't be expected to work. |
It can be expected to work if you do this in completely different class loaders. And class loaders created from classpaths in different configurations should be expected to work if those alternative configurations do not have a stray scala-library.jar. If sbt is mixing up scala-library.jar across configurations, this is a bug and it should be fixed. Configurations should be completely isolated from each other in terms of dependency resolution and classpath construction. |
In Scala.js, we use a similar mechanism to depend on a specific version of Jetty for use (via classloader) by our sbt plugin. See here: https://github.com/scala-js/scala-js/blob/v0.6.13/sbt-plugin/src/main/scala/org/scalajs/sbtplugin/ScalaJSPluginInternal.scala#L948-L962 The fact that our mechanism works for the jetty dependency, and that scalafmt's mechanism stopped working for the scala-library dependency, is a clear indicator that sbt is messing with scala-library in ways it shouldn't do. |
And to finish with a more constructive comment (instead of sounding like a rant), the above:
means that this thing is definitely fixable ;) And that's the direction in which we should look to solve the issue. |
Ivy configurations are meant to be a dependency graph on its own, so if the plugin authors create a sandbox configuration that does not depend on That does conflict with the general design goal of the mediator added by Miles, which enforces
What do you think? |
I think I prefer the first option, as I think when you have an error because you have different major Scala versions it'll be more obvious - as opposed to a configuration-based decision. eg. I think it'll be easier to understand "here's the problem, I'm using a dependency the uses Scala 2.12", as opposed to "oh right, yeah, I should've remembered to extend Runtime" |
The second option also special-cases the topology of configurations descendant from A third option is what Olaf suggested: honour when |
@dwijnand We already special case We can introduce a new setting called |
If we want to go the configuration way, I think that's a good idea (wiring that down to the mediator, with bincompat in mind, might be really tricky though). Do you think the |
I think @eed3si9n's first option defeats a large part of the purpose of the mediator, so I find the second option a lot more appealing. |
I'm not quite getting the I think that any mechanism which mixes different versions of |
I'm not feeling the |
Could someone fill me in/point me to some info on this mediator thing. |
@milessabin I don't think it does defeat a large part: the problem in #2286 was about using dependencies that transitively depended on for example scala-reflect or scala-compiler 2.11.5 (because that was the version of scala used when they were published) while having scalaVersion set to 2.11.8. The scope was always to upgrade the minor version (x.y.Z) of the scala artefacts. But I don't see anyone against the configuration idea, so maybe that's the best choice. |
I see, thanks. IMO the configuration-based idea is better, in that case. |
It's a shame this issue was not fixed before 0.13.13. What's the next version that will address this bug? |
I guess we sort of agreed on the direction of the fix but we never assigned who's going to work on it. Once we have a fix, I'd be happy to publish 0.13.14-M1. |
Please fix asap, else scalafmt cannot be used for Scala 2.12. |
Fixes sbt#2786. Ref sbt#2634. sbt 0.13.12 added Ivy mediator that enforces scalaOrganization and scalaVersion for Scala toolchain artifacts. This turns out to be a bit too aggressive because Ivy configurations can be used as an independent dependency graph that does not rely on the scalaVersion used by Compile configuration. By enforcing scalaVersion in those graph causes runtime failure. This change checks if the configuration extends Default, Compile, Provided, or Optional before enforcing scalaVersion.
Would it be possible to use sbt 0.13.13 synthetic projects as a replacement for this custom-scope + Given that 2.10 is almost three years old now and two major versions away from the latest scala release, I think it would be nice if sbt offered a clean story for plugins to use modern scala versions. BTW, I've decided to remove the scalafmt sbt plugin in its current form https://github.com/olafurpg/scalafmt/issues/597 |
It might be a way to workaround this regression. Do users of the sbt-plugin tend to format everything in one go, or on a project-by-project basis? |
I think the most common use-case is to format everything in one go. However, does it matter? To only format a subproject, the sbt plugin can pass in different flags to the |
The next release of the scalafmt sbt plugin will use synthetic projects as a workaround for this issue, see https://github.com/olafurpg/scalafmt/pull/610. The plugin ended up being much smaller than the older plugin, which I'm very happy about. sbt 0.13.13 is nice, thanks for a fantastic release. Feel free to close this issue. |
I wouldn't close this issue simply because there exists a workaround that takes a completely different direction. The fact remains that this is a bug, and it could affect other people. |
Yeah, it's still a bug. Not closing it. |
I hit on a related issue when working with Dotty + ScalaTest: scala/scala3#5612 |
@liufengyun I thought #2828 fixed this issue in 2016. |
steps
Repo to reproduce: https://github.com/olafurpg/scalafmt/files/521826/issue485.zip
problem
Running
scalafmt
results in errorsI am unable to reproduce the issue with
sbt.version=0.13.11
in build.properties.I tried the following with no success:
However, changing to typelevel/scala fixes the issue (PR: https://github.com/olafurpg/scalafmt/pull/522):
expectation
I expected the
scalafmt
task to run without error.More specifically, I expect the 0.13.12 resolver to not evict
org.scala-lang:scala-library:2.11.8
from thescalafmt
configuration in favor oforg.scala-lang:scala-libary:2.12.0-RC1
defined in thedefault
/compile
configuration.notes
The text was updated successfully, but these errors were encountered: