Mill accessing sub-modules "not found" on import

I have a libs module which will contain submodule libaries like maths, physics, etc.

I have an app module which will consume from libs, but it’s not able to import the package.

.
├── app
│   └── src
│       └── main.scala
├── build.sc
└── libs
    └── maths
        └── src
            └── constants.scala

contents of libs/maths/src/constants.scala

package libs.maths

val Pi = 3.14

contents of app/src/main.scala

package app

import libs.maths.Pi

@main def f() =
   printtln(Pi)

I get

import libs.maths.Pi
[102] [error]   |       ^^^^
[102] [error]   |       Not found: libs

build.sc

package build
import mill._, scalalib._

object libs extends ScalaModule {
  def scalaVersion = "3.7.0"
  
  object maths extends ScalaModule {
    def scalaVersion = "3.7.0"
    
  }
}

object app extends ScalaModule {
   def scalaVersion = "3.7.0"
   def moduleDeps = Seq(libs)
}

Any help is appreciated, thanks.

You declared a dependency on module libs, but the code you try to import lives in sub-module libs.maths.

2 Likes

Ah, easy fix.

  1. Is there a way to automatically include all submodules, or must I hardcode all of them?
  2. Does what I’m doing even look sensible? I’m new to Mill.

Thanks

  1. Technically, there is some programmatic way, but I suggest to start with listing them explicitly. Since you structured your project into sub-modules, you typically don’t want to depend on everything, otherwise you could have just made one single module.

  2. It depends. If you want to place code into libs/src, it makes sense. If you just want to collect all library modules under the libs dir, there is no need to extends ScalaModule. A object libs extends Module would be enough.

1 Like