Skip to content

Commit

Permalink
Document and test workflow for aliasing external modules (#3760)
Browse files Browse the repository at this point in the history
Fixes #299

I'm a bit surprised that this just works, but it does! 

The module's `millSourcePath` and `out/` folder path remain at their
original locations as the `mill.define.Ctx` is still provided by the
top-level `ExternalModule` constructor, it's just during resolution the
added method `def` allows it to get picked up during object graph
traversal
  • Loading branch information
lihaoyi authored Oct 17, 2024
1 parent 146c120 commit 2e7e281
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/modules/ROOT/pages/fundamentals/modules.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ that is shared by the entire build: for example,
service & cache that is shared between all ``ScalaModule``s, and
`mill.scalalib.GenIdea/idea` lets you generate IntelliJ projects without
needing to define your own `Task.Command` in your `build.mill` file

== Aliasing External Modules

include::partial$example/fundamentals/modules/10-external-module-aliases.adoc[]
27 changes: 27 additions & 0 deletions example/fundamentals/modules/10-external-module-aliases/build.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Mill allows you to alias external modules via `def`. You can use this to add
// shorthand aliases for external modules that have long names, such as
// `mill.javalib.palantirformat.PalantirFormatModule` below:

package build
import mill._, javalib._

object foo extends JavaModule

def myAutoformat = mill.javalib.palantirformat.PalantirFormatModule

/** Usage

> cat src/foo/Foo.java # starts off unformatted
package foo;public class Foo{ public static void main(String[] args) {System.out.println("Hello World!");}}

> mill myAutoformat # easier to type than `./mill mill.javalib.palantirformat.PalantirFormatModule/`

> cat src/foo/Foo.java # code is now formatted
package foo;
public class Foo {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

*/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package foo;public class Foo{ public static void main(String[] args) {System.out.println("Hello World!");}}

0 comments on commit 2e7e281

Please sign in to comment.