Skip to content

Commit

Permalink
Improve example docs for assembly (#4336)
Browse files Browse the repository at this point in the history
* Add example of copying `out.jar` to `out.bat` on windows
* Add example of configuring `JAVA_OPTS` and mention `JAVA_HOME`
  • Loading branch information
lihaoyi authored Jan 16, 2025
1 parent 1e6358d commit 5197944
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .config/mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.5-130-8f256f-DIRTY3537ab30-native
0.12.5-130-8f256f-DIRTY3537ab30-native
5 changes: 5 additions & 0 deletions example/javalib/basic/1-simple/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ Test run foo.FooTest finished: 0 failed, 0 ignored, 2 total, ...
> ./out/foo/assembly.dest/out.jar --text hello # mac/linux
<h1>hello</h1>

> cp ./out/foo/assembly.dest/out.jar out.bat # windows

> ./out.bat --text hello # windows
<h1>hello</h1>

*/
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public static void main(String[] args) throws IOException {
InputStream inputStream = Foo.class.getClassLoader().getResourceAsStream("application.conf");
String conf = new String(inputStream.readAllBytes());
System.out.println("Loaded application.conf from resources: " + conf);
System.out.println("Loaded test.property: " + System.getProperty("test.property"));
}
}
4 changes: 4 additions & 0 deletions example/kotlinlib/basic/1-simple/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,8 @@ Test run finished: 0 failed, 0 ignored, 2 total, ...
> ./out/foo/assembly.dest/out.jar --text hello # mac/linux
<h1>hello</h1>

> cp ./out/foo/assembly.dest/out.jar out.bat # windows

> ./out.bat --text hello # windows
<h1>hello</h1>
*/
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ fun main(args: Array<String>) {
val conf = it.readAllBytes().toString(Charsets.UTF_8)
println("Loaded application.conf from resources: $conf")
}
println("Loaded test.property: " + System.getProperty("test.property"))
}
6 changes: 6 additions & 0 deletions example/scalalib/basic/1-simple/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ error: Missing argument: --text <str>
> ./out/foo/assembly.dest/out.jar --text hello # mac/linux
<h1>hello</h1>

> # Note that on windows you need to rename `out.jar` to `out.bat` to run it
> cp ./out/foo/assembly.dest/out.jar out.bat # windows

> ./out.bat --text hello # windows
<h1>hello</h1>

*/

//// SNIPPET:END
Expand Down
11 changes: 11 additions & 0 deletions example/scalalib/publishing/1-assembly-config/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ Loaded application.conf from resources:...
...Bar Application Conf

*/

// Note that when running the assembly directly via `./out.jar`, you can configure
// JVM flags via the `JAVA_OPTS` environment variable, and select the JVM
// to use via `JAVA_HOME`.

/** Usage

> JAVA_OPTS=-Dtest.property=1337 ./out/foo/assembly.dest/out.jar
Loaded test.property: 1337

*/
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ object Foo {
def main(args: Array[String]): Unit = {
val conf = os.read(os.resource / "application.conf")
println("Loaded application.conf from resources: " + conf)
println("Loaded test.property: " + System.getProperty("test.property"))
}
}
10 changes: 8 additions & 2 deletions testkit/src/mill/testkit/ExampleTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ class ExampleTester(
|------------------------------""".stripMargin
)

val windowsPathEnv =
if (!Util.windowsPlatform) Map()
else Map(
"BASH_ENV" -> os.temp("export PATH=\"/c/Program Files/Git/usr/bin:$PATH\"").toString()
)

val res = os.call(
(bashExecutable, "-c", commandStr),
stdout = os.Pipe,
stderr = os.Pipe,
stderr = os.Inherit,
cwd = workspacePath,
mergeErrIntoOut = true,
env = IntegrationTester.millTestSuiteEnv,
env = IntegrationTester.millTestSuiteEnv ++ windowsPathEnv,
check = false
)

Expand Down

0 comments on commit 5197944

Please sign in to comment.