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

SBT scalafix does not work #38

Closed
dario01 opened this issue Jan 1, 2017 · 8 comments
Closed

SBT scalafix does not work #38

dario01 opened this issue Jan 1, 2017 · 8 comments

Comments

@dario01
Copy link

dario01 commented Jan 1, 2017

With the following steps the sbt-test fails for me, not sure what I am doing wrong?

Output:

[error] p1/src/test/scala/Test.scala
[error] File: p1/src/test/scala/Test.scala
[error] Obtained output:
[error] object TestMain {
[error] implicit val x = 2
[error] lazy val y = 2
[error] def main(args: Array[String]) {
[error] println("hello")
[error] }
[error] }
[error] Expected:
[error] object TestMain {
[error] implicit val x: Int = 2
[error] lazy val y = 2
[error] def main(args: Array[String]): Unit = {
[error] println("hello")
[error] }
[error] }
...

olafurpg added a commit to olafurpg/scalafix that referenced this issue Jan 2, 2017
olafurpg added a commit to olafurpg/scalafix that referenced this issue Jan 2, 2017
olafurpg added a commit to olafurpg/scalafix that referenced this issue Jan 2, 2017
olafurpg added a commit to olafurpg/scalafix that referenced this issue Jan 2, 2017
olafurpg added a commit that referenced this issue Jan 2, 2017
@olafurpg
Copy link
Contributor

olafurpg commented Jan 2, 2017

Thank you for reporting! I am able to reproduce on the 0.2.1 release but not on master branch. I added several new tests in #39 while trying to track down the issue but still no luck. Weird, maybe I botchered the 0.2.1 release. I just published 0.2.2-RC1 to see if the release process is the culprit.

@olafurpg
Copy link
Contributor

olafurpg commented Jan 2, 2017

I am not able to reproduce the issue on 0.2.2-RC1. If you can confirm this is also the case for you, then I will go ahead and publish it as 0.2.2.

@dario01
Copy link
Author

dario01 commented Jan 2, 2017

I can still reproduce the issue in 0.2.2-RC1 as follows:

  • git clone https://github.com/scalacenter/scalafix
  • cd ./scalafix/scalafix-sbt/src/sbt-test/sbt-scalafix/basic
  • echo 'addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.2.2-RC1" )' > ./project/plugins.sbt
  • sbt clean compile scalafix check

@olafurpg
Copy link
Contributor

olafurpg commented Jan 2, 2017

This is weird, I can reproduce the error on a clean ivy cache but not after I've published the library locally. That explains why CI is green but the sbt plugin still doesn't work. The biggest surprise to me is that the scalafix command exists silently without errors, I wonder what could be happening.

It's been a real challenge to cross-build the core to 2.11/12 while keeping the sbt plugin 2.10 only.

olafurpg added a commit to olafurpg/scalafix that referenced this issue Jan 2, 2017
olafurpg added a commit to olafurpg/scalafix that referenced this issue Jan 2, 2017
@dario01
Copy link
Author

dario01 commented Jan 2, 2017

It may have to do with the jar being published for 2.11 instead of 2.10.

Mine is for example published here:
~/.ivy2/local/ch.epfl.scala/scalafix-nsc_2.11/0.2.1/jars/scalafix-nsc_2.11.jar

@olafurpg
Copy link
Contributor

olafurpg commented Jan 2, 2017

Can you try with 0.2.0-RC3? I am now unable to reproduce the problem on a machine with empty ivy cache. The problem appears to be that publishLocal produces jars with name VERSION/scalafix-nsc_2.11.jar while the jars that get published to maven are named scalafix-nsc_2.11-VERSION.jar. The sbt plugin needs to extract the jar absolute path to correctly set -Xplugin:/.../scalafix-nsc.jar.

@dario01
Copy link
Author

dario01 commented Jan 2, 2017

I tried with 0.2.2-RC3 (not 0.2.0-RC3) and it all works great.

Yes, I had added earlier the -Xplugin: setting manually during sbt session to unblock myself.

Note that in addition to sbt publishLocal there is also sbt publishM2, perhaps it helps debugging these kind of issues in the future.

Would it be simpler if as part of the sbt setup instructions we also had:
libraryDependencies += "ch.epfl.scala" %% "scalafix-nsc" % scalafixVersion

@olafurpg
Copy link
Contributor

olafurpg commented Jan 3, 2017

Awesome! Yes, good catch, I meant 0.2.2-RC3.

Would it be simpler if as part of the sbt setup instructions we also had: libraryDependencies += "ch.epfl.scala" %% "scalafix-nsc" % scalafixVersion

That wouldn't necessarily help since scalafix-nsc is a compiler plugin, which are treated by sbt in a special way. I tried addCompilerPlugin but that did not work for some reason. The current setup is modeled after scoverage, but I deviated a bit on how to handle the jar extraction (which was the cause of this bug). I hope we won't hit on more related issues : )

I'll go ahead and publish 0.2.2 then!

@olafurpg olafurpg closed this as completed Jan 3, 2017
olafurpg added a commit to olafurpg/scalafix that referenced this issue Aug 19, 2019
bjaglin pushed a commit to liancheng/scalafix that referenced this issue May 23, 2023
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

No branches or pull requests

2 participants