Skip to content

Simplify usage of Scala 3 nightlies #6631

Open

Description

@Gedochao

Is your feature request related to a problem? Please describe.
Usage of Scala 3 nightlies with Mill is currently still a bit complex.

Describe the solution you'd like

  • get rid of the need to use a dedicated JvmWorker
  • add dedicated Mill api for getting the latest nightly (preferably with a given prefix), rather than passing an explicit version
  • automatically adding the nightly repository if a Scala version with the -NIGHTLY suffix is used

That way, instead of the current:

package build

import mill.*
import mill.api.*
import mill.scalalib.*

object JvmWorker extends JvmWorkerModule {
  override def repositories =
    super.repositories() ++ Seq(CoursierModule.KnownRepositories.ScalaLangNightlies)
}

object foo extends ScalaModule {
  override def jvmWorker: ModuleRef[JvmWorkerModule] = ModuleRef(JvmWorker)
  override def repositories =
    super.repositories() ++ Seq(CoursierModule.KnownRepositories.ScalaLangNightlies)
  override def scalaVersion = "3.8.0-RC1-bin-20250825-ee2f641-NIGHTLY"
  override def mvnDeps = Seq(
    mvn"org.scala-lang.modules::scala-xml:2.4.0"
  )
}

We could have something more like:

package build

import mill.*
import mill.api.*
import mill.scalalib.*

object foo extends ScalaModule {
  override def scalaVersion = ScalaModule.scala3LatestNightly
  override def mvnDeps = Seq(
    mvn"org.scala-lang.modules::scala-xml:2.4.0"
  )
}

Motivation
The complexity of using a nightly version with Mill makes it discouraging for users.
We'd like nightlies to be easy to test, so that the newest compiler changes can be verified in users' projects.
This in turn could make regression reports reach the Scala 3 compiler team faster.

Currently, to use the nightly one has to

  • look up the explicit nightly version manually
  • figure out the necessary repo and JvmWorker shenenigans
    • probably first just pass the version and be surprised it doesn't work
  • this could be way simpler

Activity

  1. lihaoyi commented on Jan 28, 2026

    @lihaoyi
    Member

    the custom JvmWorker is needed to let us override repositories. If we solve #5874, then most of this boilerplate goes away with a single repositories override in the build header that can apply globally to all local and external modules, including the default JvmWorkerModule so we don't need to define our own custom one

  2. lihaoyi commented on Jan 29, 2026

    @lihaoyi
    Member

    Actually it seems like we can fix things to let repositories work properly even without fiddling with global config

  3. Gedochao commented on Jan 29, 2026

    @Gedochao
    ContributorAuthor

    @lihaoyi Could we also have the API to automatically refer to the latest nightly, like in the example? (rather than to have to explicitly pass the version string)

  4. lihaoyi commented on Jan 29, 2026

    @lihaoyi
    Member

    @Gedochao currently we pass all these group-artifact-version data to coursier, which I think supports a latest.release version that dynamically picks the most recent upload based on the current maven-metadata.xml file published on the package repository. Would that satisfy your needs?

  5. Gedochao commented on Jan 29, 2026

    @Gedochao
    ContributorAuthor

    @lihaoyi So users would have to know they have to include the reference to the nightly repo in the yaml header, and then pass latest.release as the Scala version.
    Which would change the meaning between the latest nightly and latest stable/RC, depending on what repositories are there.
    While better, IMO that's still unnecessarily complex.

    The intention really was for users to not have to think about either of these things, and just get the latest nightly with a single switch.
    With Scala CLI, one does not have to explicitly pass the repository, the tool can figure out that a version with the -NIGHTLY suffix, or one of the nightly aliases, will require to use https://repo.scala-lang.org.

    With Scala CLI, I can

    scala-cli -e 'println("Hello")' -S nightly

    or

    scala-cli -e 'println("Hello")' -S 3.8.3-RC1-bin-20260129-40075f7-NIGHTLY

    The repository is added implicitly.
    Mill could go similarly with something like:

    package build
    
    import mill.*
    import mill.api.*
    import mill.scalalib.*
    
    object foo extends ScalaModule {
      override def scalaVersion = ScalaModule.scala3LatestNightly
    }

    The idea is to shorten the path to using the latest nightly down to the bare minimum, to encourage more people to test their projects with it (and raise issues early).

    If necessary, I can break it down to smaller tickets (implicit detection of the need for a nightly Scala repo and latest nightly API could be separate steps).

  6. Gedochao commented on Jan 29, 2026

    @Gedochao
    ContributorAuthor

    The idea behind #6630 is very similar, BTW.
    Not enough people test their projects with nightlies and RCs.

  7. Gedochao commented on Jan 29, 2026

    @Gedochao
    ContributorAuthor

    ...should we reopen, or do I open the follow-up tickets?

  8. lefou commented on Jan 29, 2026

    @lefou
    Member

    I think solutions must not be equally accessible in Mill as in Scala CLI. Scala CLI is mainly an low entry point to Scala, so easy access to nightlies makes sense. Mill OTOH is a build tool to help users build robust software the easy way. While testing against a nightly should be a use case, there is some benefit in being a bit harder than selecting a stable version, since using dynamic versions in a build is what we in general don't recommend. If we make it less friction to go with the always latest version dynamically then choosing a stable version, it will end up being the go-to setup for users, compromizing the applicability of the built project. At least, that is what I perceive from supporting build tools users for a very long time. For example, since Scala Steward makes it so easy to bump Mill versions, some Mill plugin projects often bumped the Mill version, resulting in plugins potentially no longer working with older Mill versions. Even if I told them that they may loose compatibility, in the end the easyness of the wrong approach makes it rule over the more correct approach.

  9. added this to the 1.1.1 milestone on Jan 29, 2026
  10. lihaoyi commented on Jan 29, 2026

    @lihaoyi
    Member

    @Gedochao with #6713, the user won't need to tweak the build header. They'd just need to set the scalaVersion and repositories on their module

    scalaVersion: 3.8.3-RC1-bin-20260128-3882481-NIGHTLY
    repositories:
    - https://repo.scala-lang.org/artifactory/maven-nightlies/
    def scalaVersion = "3.8.3-RC1-bin-20260128-3882481-NIGHTLY"
    def repositories = Seq("https://repo.scala-lang.org/artifactory/maven-nightlies/")

    I wonder if latest.release would work with these maven-nightlies repositories? I'm not super familiar with how that stuff works in Coursier, @alexarchambault do you know?

  11. Gedochao commented on Jan 29, 2026

    @Gedochao
    ContributorAuthor

    They'd just need to set the scalaVersion and repositories on their module

    But why is setting the repository explicitly necessary here? isn't it implicit, when user passes a nightly version already?
    Will the failure to get the version at least mention what repository is missing?

  12. lihaoyi commented on Jan 29, 2026

    @lihaoyi
    Member

    Passing the repository explicitly is just how repositories work on the JVM I guess? Don't most build tools require you to add non-default repositories explicitly if you want to use them?

  13. Gedochao commented on Jan 29, 2026

    @Gedochao
    ContributorAuthor

    What perhaps adds to the confusion here, is that we only recently moved our nightlies to a separate repository (https://www.scala-lang.org/news/new-scala-nightlies-repo.html).
    Up till very recently, they were on Maven Central, and I bet many users are still unaware of this change.
    I'd argue it very much is a default for nightly builds (no other way around it), and with Mill being a Scala-centric build tool, it'd make sense to cross that distance for the user.

  14. lbialy commented on Jan 29, 2026

    @lbialy
    Contributor

    I think solutions must not be equally accessible in Mill as in Scala CLI. Scala CLI is mainly an low entry point to Scala, so easy access to nightlies makes sense. Mill OTOH is a build tool to help users build robust software the easy way.

    As a counterpoint to this, it's a regular occurrence that people want to see how things will look like with a new feature (named tuples come to mind the most) in their actual work project and then come asking on discord or reach out via a dm with questions on how to take the newest version for a test drive. This is exactly the scenario we're interested in easing as once more people do this, interesting compilation errors from Scala code in the wild will be encountered earlier and hopefully reported earlier. The notion that by making something a bit more obscure and more difficult to use you're preventing dumb mistakes seems naive to me, people were fine with things like webpack config files for years 😆 If anything would help to prevent wrong usage, it would be probably a note in docs and a mill runtime warning informing that this configuration is NOT to be used for production purposes and it's for experimentation only.

    I personally find the snippet proposed by @Gedochao very straightforward and intuitive - it's a Scala module so obviously I can switch version of the language to a nightly without much fuss. The nightly repository and the need of having the knowledge that it exists seems like an implementation detail of the language's infrastructure. Other langs encode things like this into the build tool ecosystem to remove friction. As a famous reference point - in Rust it's just cargo +nightly build or

    cat > rust-toolchain.toml << EOF
    [toolchain]
    channel = "nightly"
    EOF
    

    if you want to execute all cargo commands with a latest nightly in this project.

  15. lefou commented on Jan 29, 2026

    @lefou
    Member

    Maybe, instead of fiddling with some dedicated version suffix, and splattered logic in various places, users could mix-in a ScalaNightly trait, which adds whatever is needed to bring a nightly into the game: repositories, find newest version, print warnings, offline support, ...

    Those traits can also be added in build.mill.yaml files easily with extends: ScalaNightly

  16. lihaoyi commented on Jan 29, 2026

    @lihaoyi
    Member

    If you think 2 lines of config to use nightlies is too much, I think making using nightlies even easier is fine.

    Since nightlies need to override multiple tasks, making support a trait that users can extends ScalaNightly would be the canonical way to do it, as @lefou mentioned. That would bring the 2 lines down to 1

    @Gedochao @lbialy Perhaps you guys could send a PR to implement this? You can implement your trait in the build.mill of your own test project, make sure it works, then just paste the trait over to libs/scalalib/src/ and send a PR and it should just work for others. Maybe add a unit test in libs/scalalib/test/src/

  17. Gedochao commented on Jan 30, 2026

    @Gedochao
    ContributorAuthor

    Lemme see what I can do.
    @lihaoyi Can we reopen the issue? You can assign it to me.

  18. lefou commented on Jan 30, 2026

    @lefou
    Member

    @lbialy I already proposed a compromise which should be easy to use and explicit. But just to be clear about it ...

    The notion that by making something a bit more obscure and more difficult to use you're preventing dumb mistakes seems naive to me

    I was not arguing for making it more obscure and difficult. IMHO it is already easy and standard, but not as easy as you wished. The decision to publishing nightlies into a different repository wasn't made here and there were most likely good reasons for it.

    If anything would help to prevent wrong usage, it would be probably a note in docs and a mill runtime warning informing that this configuration is NOT to be used for production purposes and it's for experimentation only.

    I already said before, that in my experience, this is not going to stop maintainers from doing it, with hidden casualties downsteam. If doing something wrong is hard to recognize (only downstream users may have issues, if any) but easier to apply than the correct way, there will be some users choosing that route, since it is (on first sight) a maintenance free way to stay up to date. Understanding why it might not be a good idea costs a much higher learning/thinking effort.

  19. removed this from the 1.1.1 milestone on Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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