Skip to content

binary distribution: package information about jars required for scalac classpath in a separate file #20413

Closed
@unkarjedy

Description

@unkarjedy

Context:

In IntelliJ IDEA, you can use a plain IntelliJ project without build system SBT/Maven/Gradle/BSP.
In Scala Plugin we have a concept of "Scala SDK" which simply represents the scala compiler (classpath) and scala version.
In case the user already has Scala "installed" (whatever that means) IntelliJ has some logic to detect it.
We have multiple kinds of detectors for Brew, SDKMAN, Coursier, Maven, Ivy.

We also have a "System" detector which can detect Scala SDK from the unzipped binary Scala distribution (see Assets at github)
To construct Scala Compiler classpath, we read some jars from lib directory.

In Scala2 the code of constructing the classpath was quite simple. We just search for a fixed set of compiler jars: scala-compiler-2.X.Y.jar, scala-library-2.X.Y.jar, scala-reflect-2.X.Y.jar:

image

Issue

In Scala3 things get different. Scala 3 compiler classpath has more dependencies on more libraries.
In general, each minor/major Scala 3 version can have dependencies on different libraries with different versions.
We can't just include all jars from lib folder. We need an explicit list of compiler classpath dependencies because lib folder contains a lot of other jar files, not required for the compiler. AFAIU most of them are needed for scaladoc, not scalac.

image

With Maven/Coursier/Ivy detectors, we can live with it because we can resolve transitive dependencies for scala3-compiler_3 and get the classpath.
However, with System detector we can't do it.
Three years ago I provided a hardcoded solution for Scala 3.0.0 (see the code)
It worked up to Scala 3.3.1 but shot back in 3.3.2 & 3.4.x (see https://youtrack.jetbrains.com/issue/SCL-22510).

Proposal

I think the only reliable solution is that along with the jar files, scala compiler publishes the classpath required for scalac.
For consistency, it could also publish the classpath for Scaladoc.
For example, it could be just two files:

  • lib/scalac-classpath
  • lib/scaladoc-classpath

Those files could contain a list of jar names or even jar name patterns on every line.
Then in IntelliJ we could simply read that file content.
If you have better ideas on the file names/format, we can discuss it.

Notes

Note that the information about scalac/scaladoc classpath is already known to the code which does the binary distribution packaging. It's already present in bin/common, bin/common.bat, bin/scaladoc, bin/scaladoc.bat.
However, it would be a too fragile solution to rely on those files as their structure can change and our parsing logic can break.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions