scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Detect compile-time dependencies, detect unused compile-time dependencies

Open igor-ramazanov opened this issue 3 months ago • 0 comments

Is your feature request related to a problem? Please describe. https://github.com/cb372/sbt-explicit-dependencies and https://github.com/kierendavies/mill-explicit-deps are handy plugins to:

  • find unused compile-time dependencies
  • explicitly list all compile-time dependecies
  • verify all compile-time deps are explicit and there're no unused compile-time deps

It helps to maintain a stricter and cleaner build.

For example, you have //> using dep A which brings in a transitive library C of version 1 (C1), then //> using dep B bringing a transitive library C of version 2 (C2).

Neither C1 or C2 are listed in project.scala.

The C2 gets picked in the runtime, and also referred to in the source code.

But we would never know it just by looking at the project.scala.

Describe the solution you'd like Similar functionality in any form.

Not sure how exactly it'd would look like from an end-user perspective.

As a personal note, I don't like adding more flags/commands and instead in favour of careful thinking of defaults and the API itself.

During editing the project.scala, the most straightforward approach seems to be an LSP code action: "add all compile-time dependencies" and "remove unused compile-time dependencies".

On the other hand, I'm not sure how to mirror it in CLI. Adding flags to the scala-cli fix? Perhaps, it'd be too much to make it a default behavior of scala-cli fix. Maybe as flags? scala-cli fix --with-explicit-deps --with-unused-deps? 🤷‍♂️

Describe alternatives you've considered A hacky external solution by traversing the classpath sources and checking which dep responsible for which import?

Additional context It'll allow to be 100% sure of what deps are actually used in the build.

igor-ramazanov avatar Sep 18 '25 14:09 igor-ramazanov