Closed uosis closed 5 months ago
Thanks for the report! So the exception stacktrace is shown in IDEA when you build the whole project? It seems to come from IDEA itself, not Mill, and should reported there, too. Maybe we generate the settings not the way they expect, but we have no control over any copy processes IDEA thinks it has to run.
About the other issue:
<orderEntry type="library" name="scala-library-2.13.10.jar" level="project"/> <orderEntry type="library" name="scala3-library_3-3.3.1.jar" level="project"/>
It looks like just re-ordering these two entries and making the scala3_library
come first fixes the issue for me.
<orderEntry type="library" name="scala3-library_3-3.3.1.jar" level="project"/>
<orderEntry type="library" name="scala-library-2.13.10.jar" level="project"/>
Can you confirm this also works for you? I'd favor this solution over yours, as your fix refers to some application level library we don't control and therefore also can't guarantee to exists.
So the exception stacktrace is shown in IDEA when you build the whole project?
Correct, when doing "Build Project" from IDEA.
Removing <sourceFolder url="file://$MODULE_DIR$/../../build.sc" isTestSource="false"/>
line from mill-build.iml
fixes the problem, but I am not sure what in 0.11.5 caused it to start happening.
Can you confirm this also works for you? I'd favor this solution over yours, as your fix refers to some application level library we don't control and therefore also can't guarantee to exists.
Confirmed reordering also works. I also favor this solution. That application library was just a default added by IDEA when creating Scala project from IDEA (vs import). It is irrelevant otherwise.
I came across the same issues with mill 0.11.6 and IDEA 2023.3.1. I can confirm that the proposed reordering resolves the issues. Will mill.scalalib.GenIdea/idea
be fixed anytime soon? I would like to finish the migration from mill 0.10 to 0.11.
Having more than one issue in one ticket is a bad idea, as it always makes working on it harder. First when you review it, later, when you're looking for open tasks, then again when you want to address is via a link, and so on. Next time, please open each issue in it's own ticket.
I think the main issue is the order of the Scala library path entries. A proposed solution is to always have the Scala 3 entry before the Scala 2 entry, which was reported to fix the issue in https://github.com/com-lihaoyi/mill/issues/2867#issuecomment-1854687374 and https://github.com/com-lihaoyi/mill/issues/2867#issuecomment-1810973970.
Some more details about the implementation.
When I played with the implementation last year, I noticed a fix is not as trivial as re-ordering the scala-library
entries. We currently attach additional details to a scala- library
entry, specifically the scalaCompilerClasspath
. Therefore, we need to make sure we don't attach the wrong scala compiler (Scala 3) to a Scala library in a Scala 2 module. There might be a small risk we produce an invalid IDEA project when we have modules with Scala 3 and Scala 2. I don't remember exactly how, but when I was just reorder the entries, I hit some more complexities because of that.
Once I find the branch/stash again, I can share my work on this issue.
Hello!
I am from the IntelliJ Scala Plugin team. I found this issue after a question in our Discord
We had a similar issue with SBT projects some time ago: https://youtrack.jetbrains.com/issue/SCL-18866/sbt-module-can-wrongly-depend-on-scala-sdk-instead-of-normal-scala-library-in-multi-module-projects For some time we used a workaround which would pick the Scala SDK with the largest version. But the issue with SBT was fixed by having a better project structure, and the workaround was removed (which could affect Mill implicitly)
Here are some insights from our fix for SBT: It's better to separate Scala SDK and Scala Library concepts and represent them by two separate entities.
Below is an example of a simple SBT project structure. Notice that Scala SDK node doesn't have any "Standard library" entries. Also notice that there are 2 plain library nodes, for Scala 2 and for Scala3
The file contents are as follows:
<component name="libraryTable">
<library name="sbt: org.scala-lang:scala3-library_3:3.3.3:jar" external-system-id="SBT">
<CLASSES>
<root url="jar://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.3/scala3-library_3-3.3.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.3/scala3-library_3-3.3.3-sources.jar!/" />
</SOURCES>
</library>
</component>
<component name="libraryTable">
<library name="sbt: org.scala-lang:scala-library:2.13.12:jar" external-system-id="SBT">
<CLASSES>
<root url="jar://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12-sources.jar!/" />
</SOURCES>
</library>
</component>
<component name="libraryTable">
<library name="sbt: scala-sdk-3.3.3" type="Scala">
<properties>
<language-level>Scala_3_3</language-level>
<scaladoc-extra-classpath>
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.15.1/jackson-annotations-2.15.1.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.15.1/jackson-core-2.15.1.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.15.1/jackson-databind-2.15.1.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.15.1/jackson-dataformat-yaml-2.15.1.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.12.1/jackson-datatype-jsr310-2.12.1.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-anchorlink/0.62.2/flexmark-ext-anchorlink-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-autolink/0.62.2/flexmark-ext-autolink-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-emoji/0.62.2/flexmark-ext-emoji-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-gfm-strikethrough/0.62.2/flexmark-ext-gfm-strikethrough-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-gfm-tasklist/0.62.2/flexmark-ext-gfm-tasklist-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-ins/0.62.2/flexmark-ext-ins-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-superscript/0.62.2/flexmark-ext-superscript-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-tables/0.62.2/flexmark-ext-tables-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-wikilink/0.62.2/flexmark-ext-wikilink-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-ext-yaml-front-matter/0.62.2/flexmark-ext-yaml-front-matter-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-jira-converter/0.62.2/flexmark-jira-converter-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-ast/0.62.2/flexmark-util-ast-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-builder/0.62.2/flexmark-util-builder-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-collection/0.62.2/flexmark-util-collection-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-data/0.62.2/flexmark-util-data-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-dependency/0.62.2/flexmark-util-dependency-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-format/0.62.2/flexmark-util-format-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-html/0.62.2/flexmark-util-html-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-misc/0.62.2/flexmark-util-misc-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-options/0.62.2/flexmark-util-options-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-sequence/0.62.2/flexmark-util-sequence-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util-visitor/0.62.2/flexmark-util-visitor-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark-util/0.62.2/flexmark-util-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/vladsch/flexmark/flexmark/0.62.2/flexmark-0.62.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/nl/big-o/liqp/0.8.2/liqp-0.8.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jetbrains/annotations/15.0/annotations-15.0.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jsoup/jsoup/1.17.2/jsoup-1.17.2.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/nibor/autolink/autolink/0.6.0/autolink-0.6.0.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-tasty-inspector_3/3.3.3/scala3-tasty-inspector_3-3.3.3.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scaladoc_3/3.3.3/scaladoc_3-3.3.3.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/yaml/snakeyaml/2.0/snakeyaml-2.0.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/ua/co/k/strftime4j/1.0.5/strftime4j-1.0.5.jar" />
</scaladoc-extra-classpath>
<compiler-classpath>
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.3/scala3-library_3-3.3.3.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-reader/3.19.0/jline-reader-3.19.0.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-terminal-jna/3.19.0/jline-terminal-jna-3.19.0.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jline/jline-terminal/3.19.0/jline-terminal-3.19.0.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-asm/9.5.0-scala-1/scala-asm-9.5.0-scala-1.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.3.3/scala3-compiler_3-3.3.3.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-interfaces/3.3.3/scala3-interfaces-3.3.3.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/tasty-core_3/3.3.3/tasty-core_3-3.3.3.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/compiler-interface/1.9.3/compiler-interface-1.9.3.jar" />
<root url="file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/util-interface/1.9.2/util-interface-1.9.2.jar" />
</compiler-classpath>
<compiler-bridge-binary-jar>file://$USER_HOME$/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-sbt-bridge/3.3.3/scala3-sbt-bridge-3.3.3.jar</compiler-bridge-binary-jar>
</properties>
<CLASSES />
<JAVADOC />
<SOURCES />
</library>
</component>
Note that scaladoc-extra-classpath
is optional.
It would be only used for "Generate Scaladoc" action.
SBT reports it Mill also could, but again, it's optional.
Related: 1, 2
In case you have any other questions related to IntelliJ Scala Plugin welcome to our https://discord.com/channels/931170831139217469/931171260824707072
If you have any issue to report, please use https://youtrack.jetbrains.com/newIssue?project=SCL
Also, maybe you could take a look at https://discord.com/channels/632150470000902164/635669047588945930/1214624102892183653 ?
@unkarjedy Thank you very much for you comments. I think the idea of introducing a scala-sdk entry looks like a nice solution. I'd tried to fix this before, but the fact the the compiler info was attached to one of the scala libraries was hard to fix without major reorganizations. Once I find the time, I will revisit this issue and try to come up with a solution based on your insights.
@unkarjedy Is there somewhere some documentation about the xml formats? E.g. the what the external-system-id
means and why there is the sbt:
prefix in the library names?
Is there somewhere some documentation about the xml formats? E.g. the what the external-system-id means
No, there is no such documentation. The serialisation format of XML files is an implementation detail. This particular tag comes from here. There is some documentation about the related field here
and why there is the sbt: prefix in the library names?
To my knowledge, there is no documentation on this as well. The prefix is added automatically by the platform when you when the build-system integration is written via External System API. It's done so for other build tools as well (e.g. Maven, Gradle) JFTR, the is added here
Anyway, AFAIU the prefix is not mandatory.
On the Mill site, in the section "IntelliJ IDEA Support" there is this paragraph:
Additionally, you can generate IDEA project files directly with Mill. This is probably the preferred way if you work on polyglot projects and need support for other languages like Kotlin or AspectJ, which are currently not specifically configured over BSP. To generate IntelliJ IDEA project files into .idea/, run:
mill mill.idea.GenIdea/idea
I don't know the profile of average Mill user and how frequently they have mixed Kotlin/Scala projects. But have you ever re-evaluated this? To integrate with Kotlin, some other code would need to generate Kotlin-specific XML-files. And that code would most likely not know anything about the XML files generated by Mill.
Maintaining mill mill.idea.GenIdea/idea
, not as an IntelliJ plugin but as a standalone command relying on internal serialisation format might be hard and fragile.
At first glance, BSP approach should be more promoted as the default way to work in IntelliJ.
But I don't have a full context of Mill and can miss something.
BTW BSP-IntelliJ integration is not mentioned in the README
Thank you @unkarjedy for all the insights. I agree that BSP should be the preferred IDE integration. An yet, in polyglot projects, you still have more options when you directly generate .idea
files compared to BSP. Some plugins use the ability to generate additional files, e.g. mill-aspectj
(https://github.com/lefou/mill-aspectj/blob/main/aspectj/src-0.11/de/tobiasroeser/mill/aspectj/AspectjIdeaSupport.scala), and in a project I work with, we customize the mill-kotlin
plugin to generate project IDEA config files with compiler plugin configurations.
But I see that IDEA is using BSP for more languages nowadays, so I'm happy to revisit that. And I encourage users who find things work well to report back and update the documentation.
Fixed in 0.11.7-86-18d144
build.sc:
milltest/src/Main.scala:
Using Mill 0.11.5:
./mill mill.idea.GenIdea/idea
Probably caused by https://github.com/com-lihaoyi/mill/pull/2638, so downgrade Mill to 0.11.1:
./mill mill.scalalib.GenIdea/idea
.idea/mill_modules/milltest.iml
and replacewith