JetBrains / sbt-idea-plugin

Develop IntelliJ plugins with Scala and SBT
Apache License 2.0
97 stars 28 forks source link

scalac: Multiple 'scala-library*.jar' files #96

Closed moglideveloper closed 3 years ago

moglideveloper commented 3 years ago

Try to open attached simplified intellij plugin in intellij that depends on sbt-idea-plugin.

It will download and load multiple scala-library* configuration in .idea directory from below locations :- ~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/ ~/.samplePluginIC/sdk/LATEST-EAP-SNAPSHOT/plugins/Scala/lib/

This is tried on a clean machine with just open-jdk 11 and the itellij community edition(with scala plugin) installed.

Below are the entries of scala-library inside SamplePlugin/.idea directory :-

#below command is executed from SamplePlugin/.idea
grep -r "scala-library*" . | egrep -v "doc|source" | cut -d ":" -f1 | uniq | xargs -I {} bash -c "echo {}; grep "scala-library*" {}; echo "--------------""

./libraries/sbt__org_scala_lang_scala_library_2_13_2_jar.xml
  <library name="sbt: org.scala-lang:scala-library:2.13.2:jar" type="Scala">
        <root url="file://$USER_HOME$/.samplePluginIC/sdk/LATEST-EAP-SNAPSHOT/plugins/Scala/lib/scala-library-2.13.2.jar" />
        <root url="file://$USER_HOME$/.samplePluginIC/sdk/LATEST-EAP-SNAPSHOT/plugins/Scala/lib/scala-library.jar" />
        <root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.2/scala-library-2.13.2.jar" />
      <root url="jar://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.2/scala-library-2.13.2.jar!/" />
      <root url="jar://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.2/scala-library-2.13.2-javadoc.jar!/" />
      <root url="jar://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.2/scala-library-2.13.2-sources.jar!/" />
--------------
./libraries/sbt__JetBrains_org_intellij_scala_2020_3_20_IJ_PLUGIN_jar.xml
      <root url="jar://$USER_HOME$/.samplePluginIC/sdk/LATEST-EAP-SNAPSHOT/plugins/Scala/lib/scala-library-2.13.2.jar!/" />
      <root url="jar://$USER_HOME$/.samplePluginIC/sdk/LATEST-EAP-SNAPSHOT/plugins/Scala/lib/scala-library.jar!/" />
--------------
./modules/sample-build.iml
          <root url="jar://$USER_HOME$/.sbt/boot/scala-2.12.10/lib/scala-library.jar!/" />
--------------
./modules/sample.iml
    <orderEntry type="library" scope="PROVIDED" name="sbt: org.scala-lang:scala-library:2.13.2:jar" level="project" />
--------------

Above configuration results in scalac: Multiple 'scala-library*.jar' files (scala-library-2.13.2.jar, scala-library.jar, scala-library-2.13.2.jar) in Scala compiler classpath in Scala SDK sbt: org.scala-lang:scala-library:2.13.2:jar

Below is a simplified example to reproduce this problem :- https://github.com/moglideveloper/SamplePlugin

mutcianm commented 3 years ago

The library sbt: org.scala-lang:scala-library:2.13.2:jar must not contain all those jars from $USER_HOME$/.samplePluginIC/sdk/LATEST-EAP-SNAPSHOT I'm able to reproduce the misconfigured library classpath, but the compilation still works in my case perhaps due to a different classpath ordering. As a quick workaround you can manually remove those bogus classpath entries while I'm working on a fix

jerrytheprogrammer commented 3 years ago

Thanks @mutcianm for work-around. I tried removing suggested bogus entries, but now I am getting below error :- scalac: No 'scala3-compiler*.jar' in Scala compiler classpath in Scala SDK sbt: org.scala-lang:scala-library:2.13.2:jar

Is there any other workaround. I can run plugin from sbt, but then I will not be able to debug sample intellij plugin, as sbt -jvm-debug 5005 is also doesn't seem to be working.

mutcianm commented 3 years ago

Please try updating to the latest version - 3.12.1

jerrytheprogrammer commented 3 years ago

updating to latest version fixed problem. Thanks for quick fix.