scalabuild-toolsmill

How to create Sources from a Seq[Path] in mill build.sc file?


Mill documentation says

Sources are defined using T.sources {…​}, taking one-or-more os.Paths as arguments. A Source is a subclass of Target[Seq[PathRef]]

So this is possible in mill v0.9.9

def sourceRoots: Sources = T.sources { os.pwd / "src" }

and this

def sourceRoots: Sources = T.sources ( os.pwd / "src", os.pwd / "foobar" ) 

but these do not compile:

def sourceRoots = T.sources { os.pwd / "src", os.pwd / "foobar" }
def sourceRoots = T.sources { Seq(os.pwd / "src", os.pwd / "foobar") }
def sourceRoots = T.sources { Seq(os.pwd / "src", os.pwd / "foobar") : _* }
def sourceRoots = T.sources ( Seq(os.pwd / "src", os.pwd / "foobar") )
def sourceRoots = T.sources ( Seq(os.pwd / "src", os.pwd / "foobar") : _* )

Is it somehow possible to create def sourceRoots: Sources = T.sources ... from a seq of paths?


Solution

  • There are two overloads for T.sources construction. One accepts os.Paths, the other one accepts a Seq[mill.api.PathRef].

    To create a T.sources from a Seq[os.Path], do the following:

    val paths = Seq(millSourcePath / "src", millSourcePath / "src-jvm")
    
    def sourceRoots = T.sources { paths.map(p => PathRef(p)) }