scalacenter / scalafix

Refactoring and linting tool for Scala
https://scalacenter.github.io/scalafix/
BSD 3-Clause "New" or "Revised" License
823 stars 186 forks source link

Get IntelliJ working for the new build #456

Closed olafurpg closed 6 years ago

olafurpg commented 6 years ago

In #454 we refactored the build to escape the wrath of ++ and sbt-doge. Now the entire build stays within the task graph, even for cross-builds. This new build is significantly easier to reason about and is less fragile, but it seems it's no longer possible to run the tests or compile the project from IJ.

Here's how my "Modules" looks like

screen shot 2017-11-25 at 09 34 36

No matter if I reload, IJ still says build.sbt has changed and requires a refresh

screen shot 2017-11-25 at 09 35 06

When trying to run the tests from IJ, I get a missing dependency error screen shot 2017-11-25 at 09 24 55 even if difflib is a dependency of diff-sources (but it's not a dependency of diffJVM~1 screen shot 2017-11-25 at 09 36 41

It seems BuildInfo in src_managed of the unit project is neither picked up screen shot 2017-11-24 at 16 17 57 I was able to fix this by manually adding src_managed to "Sourcesofunit-sources` project screen shot 2017-11-25 at 09 38 30

cc/ @jastice any idea what is happening?

jastice commented 6 years ago

I reproduced the problem, it seems to be that sourceDirectories in sbt are configured to be a subdirectory of .cross:

[IJ]> unit/sourceDirectories
[info] * /Users/jast/playspace/scalafix/.cross/unit/src/main/scala-2.12
[info] * /Users/jast/playspace/scalafix/.cross/unit/src/main/scala
[info] * /Users/jast/playspace/scalafix/.cross/unit/src/main/java
[info] * /Users/jast/playspace/scalafix/scalafix-tests/unit/src/main/scala
[info] * /Users/jast/playspace/scalafix/.cross/unit/target/scala-2.12/src_managed/main

... while actually they are under the root. IntelliJ uses the sourceDirectories setting to mark directories appropriately. Not sure what you're doing here :)

olafurpg commented 6 years ago

Can you explain how you would expect sourceDirectories to look like?

[master] scalafix: show coreJVM/sourceDirectories
[info] * /Users/ollie/dev/scalafix/.cross/core/jvm/src/main/scala-2.12
[info] * /Users/ollie/dev/scalafix/.cross/core/jvm/src/main/scala
[info] * /Users/ollie/dev/scalafix/.cross/core/jvm/src/main/java
[info] * /Users/ollie/dev/scalafix/.cross/core/shared/src/main/scala-2.12
[info] * /Users/ollie/dev/scalafix/.cross/core/shared/src/main/scala
[info] * /Users/ollie/dev/scalafix/scalafix-core/shared/src/main/scala
[info] * /Users/ollie/dev/scalafix/scalafix-core/jvm/src/main/scala
[info] * /Users/ollie/dev/scalafix/.cross/core/jvm/target/scala-2.12/src_managed/main
[master] scalafix: show coreJVM/sourceDirectory
[info] /Users/ollie/dev/scalafix/.cross/core/jvm/src

We have this unorthodox setup to avoid ++. Our build has a mix of 2.10 only, 2.11/2.12 cross-build and dotty only projects. Compile in some 2.11/2.12 cross-built projects have task depend on compile in dotty/2.10 only projects, which triggered intellij to fail update.

jastice commented 6 years ago

For IDEA to pick up the directory with BuildInfo as source dir, either you would have to configure sbt-buildinfo to generate the file to <build root>/.cross/unit/target/scala-2.12/src_managed/main, or add the directory that it is generated to the sourceDirectories, i.e. <build root>/target/scala-2.12/src_managed/main

olafurpg commented 6 years ago

Thanks for the input @jastice The build seems to import fine now for some reason, no idea what changed.