-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example documentation for
ModuleRef
(#3763)
Not super thorough, but at least it exists now
- Loading branch information
Showing
6 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
example/fundamentals/modules/11-module-ref/bar/src/bar/Bar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package bar; | ||
|
||
|
||
public class Bar { | ||
public static String generateHtml(String text) { | ||
String value = "<h1>" + text + "</h1>"; | ||
return value; | ||
} | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
example/fundamentals/modules/11-module-ref/bartest/src/bar/BarTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package bar; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Test; | ||
|
||
public class BarTests { | ||
|
||
@Test | ||
public void simple() { | ||
String result = Bar.generateHtml("hello"); | ||
assertEquals("<h1>hello</h1>", result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// When you define an abstract module, often you are referencing an existing module | ||
// somewhere in your build. A naive `def upstreamModule: FooModule` | ||
// would create a module alias, which is often not what you want since the referenced | ||
// module already has a place in your build hierarchy. In such scenarios, you can use | ||
// a `ModuleRef(...)` to wrap the abstract module, such that the abstract `def` does | ||
// not participate in task query resolution: | ||
|
||
package build | ||
import mill._, javalib._ | ||
import mill.define.ModuleRef | ||
|
||
object foo extends JavaModule | ||
object bar extends JavaModule | ||
|
||
trait MyTestModule extends JavaModule with TestModule.Junit4{ | ||
def upstreamModule: ModuleRef[JavaModule] | ||
|
||
def moduleDeps = Seq(upstreamModule()) | ||
} | ||
|
||
object footest extends MyTestModule{ | ||
def upstreamModule = ModuleRef(foo) | ||
} | ||
object bartest extends MyTestModule{ | ||
def upstreamModule = ModuleRef(bar) | ||
} | ||
|
||
|
||
/** Usage | ||
|
||
> mill __.test | ||
Test foo.FooTests.simple finished, ... | ||
Test bar.BarTests.simple finished, ... | ||
... | ||
|
||
> mill resolve foo.upstreamModule._ # This fails since it's a `ModuleRef`, not just a `Module` | ||
error: resolve Cannot resolve foo.upstreamModule... | ||
*/ |
8 changes: 8 additions & 0 deletions
8
example/fundamentals/modules/11-module-ref/foo/src/foo/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package foo; | ||
|
||
|
||
public class Foo { | ||
|
||
public static final String VALUE = "hello"; | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
example/fundamentals/modules/11-module-ref/footest/src/bar/FooTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package foo; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Test; | ||
|
||
public class FooTests { | ||
|
||
@Test | ||
public void simple() { | ||
assertEquals("hello", Foo.VALUE); | ||
} | ||
} |