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

GenIdea: Scala 3 module don't work when scala-library is before scala3-library entry in iml config #2867

Closed
uosis opened this issue Nov 9, 2023 · 14 comments · Fixed by #3154
Milestone

Comments

@uosis
Copy link
Contributor

uosis commented Nov 9, 2023

build.sc:

import mill._, scalalib._

object milltest extends ScalaModule {
  def scalaVersion = "3.3.1"
}

milltest/src/Main.scala:

extension [T](obj: T) def foo: T = ???

Using Mill 0.11.5:

  • run ./mill mill.idea.GenIdea/idea
  • try to build in IDEA (IntelliJ IDEA 2023.2.4)
  • build fails with:
Resource compiler: Error: Couldn't copy [/home/user/repos/milltest/build.sc] to [/home/user/repos/milltest/out/mill-build/ideaCompileOutput.dest/classes/.]
java.io.IOException: Couldn't copy [/home/user/repos/milltest/build.sc] to [/home/user/repos/milltest/out/mill-build/ideaCompileOutput.dest/classes/.]
	at com.intellij.openapi.util.io.FileUtil.performCopy(FileUtil.java:413)
	at com.intellij.openapi.util.io.FileUtil.copyContent(FileUtil.java:402)
	at org.jetbrains.jps.incremental.FSOperations.copy(FSOperations.java:460)
	at org.jetbrains.jps.incremental.resources.ResourcesBuilder.copyResource(ResourcesBuilder.java:123)
	at org.jetbrains.jps.incremental.resources.ResourcesBuilder.lambda$build$0(ResourcesBuilder.java:67)
	at org.jetbrains.jps.incremental.fs.BuildFSState.processFilesToRecompile(BuildFSState.java:374)
	at org.jetbrains.jps.incremental.IncProjectBuilder$6.processDirtyFiles(IncProjectBuilder.java:1294)
	at org.jetbrains.jps.incremental.resources.ResourcesBuilder.build(ResourcesBuilder.java:56)
	at org.jetbrains.jps.incremental.resources.ResourcesBuilder.build(ResourcesBuilder.java:27)
	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTarget(IncProjectBuilder.java:1299)
	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1198)
	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1336)
	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1150)
	at org.jetbrains.jps.incremental.IncProjectBuilder$BuildParallelizer$1.run(IncProjectBuilder.java:1116)
	at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:249)
	at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:31)
	at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:227)
	at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:218)
	at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:215)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.nio.file.FileSystemException: /home/user/repos/milltest/out/mill-build/ideaCompileOutput.dest/classes/.: Is a directory
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:100)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
	at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:484)
	at java.base/java.nio.file.Files.newOutputStream(Files.java:228)
	at com.intellij.openapi.util.io.FileUtil.openOutputStream(FileUtil.java:446)
	at com.intellij.openapi.util.io.FileUtil.performCopy(FileUtil.java:409)
	... 21 more

Probably caused by #2638, so downgrade Mill to 0.11.1:

  • ./mill mill.scalalib.GenIdea/idea
  • build now succeeds in IDEA, but Scala 3 syntax is not recognized by IDEA
  • workaround:
    • manually edit .idea/mill_modules/milltest.iml and replace
<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"/>

with

<orderEntry type="library" name="scala-sdk-3.3.1" level="application" />
  • Scala 3 syntax is now recognized
@lefou
Copy link
Member

lefou commented Nov 10, 2023

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.

@uosis
Copy link
Contributor Author

uosis commented Nov 14, 2023

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.

@informarte
Copy link

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.

@lefou
Copy link
Member

lefou commented Dec 14, 2023

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 #2867 (comment) and #2867 (comment).

@lefou lefou changed the title Multiple GenIdea issues GenIdea: Scala 3 project don't work when scala-library comes before scala3-library entry in module config Dec 14, 2023
@lefou lefou changed the title GenIdea: Scala 3 project don't work when scala-library comes before scala3-library entry in module config GenIdea: Scala 3 module don't work when scala-library is before scala3-library entry in iml config Dec 14, 2023
@lefou
Copy link
Member

lefou commented Jan 3, 2024

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.

@unkarjedy
Copy link
Contributor

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.

  • Scala Library nodes should contain information about scala-library jars only (classes &/ sources)
  • Scala SDK should just information about the Scala compiler class path and Scala compiler version.
    If in Mill you have access to the compiler bridge path, you can also specify it.
    Otherwise, a bundled one will be used. The bundled one should work fine for the latest released Scala 3 versions, but might not work ok for newly released versions.

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
image

The file contents are as follows:

image
<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

@unkarjedy
Copy link
Contributor

unkarjedy commented Apr 19, 2024

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

@unkarjedy
Copy link
Contributor

@lefou
Copy link
Member

lefou commented Apr 20, 2024

@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.

@lefou
Copy link
Member

lefou commented Apr 20, 2024

@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?

@unkarjedy
Copy link
Contributor

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.

@unkarjedy
Copy link
Contributor

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

@lefou
Copy link
Member

lefou commented Apr 22, 2024

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.

@lefou lefou linked a pull request May 16, 2024 that will close this issue
@lefou lefou added this to the 0.11.8 milestone May 16, 2024
lefou added a commit that referenced this issue May 16, 2024
Previously, we attached the compiler setup to the scala-library entry.
This doen't work well for Scala 3 projects, since there are multiple
scala-library entries present, one for Scala 2 and one for Scala 3.
If the Scala 2 version comes first, IJ uses the wrong compiler setup.

This change splits the scala-library from the compiler setup. The
compiler setup now becomes a dedicated synthetic `scala-SDK` library
entry for each Scala module. The scala-library no longer has any special
semantic and is just an ordinary jar. Only one scala-SDK entry is added
to each Scala module resulting in a proper setup.

Fix #2867

Pull request: #3154
@lefou
Copy link
Member

lefou commented May 16, 2024

Fixed in 0.11.7-86-18d144

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

Successfully merging a pull request may close this issue.

4 participants