diff --git a/build.sc b/build.sc index 71e2afd6324..cfabf1f3cbc 100644 --- a/build.sc +++ b/build.sc @@ -1756,6 +1756,8 @@ object docs extends Module { | title: Mill | url: ${if (authorMode) s"${T.dest}/site" else Settings.docUrl} | start_page: mill::Intro_to_Mill_for_Scala.adoc + | keys: + | google_analytics: 'G-1C582ZJR85' | |content: | sources: @@ -1783,7 +1785,7 @@ object docs extends Module { | mill-github-url: ${Settings.projectUrl} | mill-doc-url: ${if (authorMode) s"file://${T.dest}/site" else Settings.docUrl} | mill-download-url: ${if (authorMode) s"file://${exampleZips().head.path / os.up}" - else s"${Settings.projectUrl}/releases/download/0.11.10"} + else s"${Settings.projectUrl}/releases/download/${millLastTag()}"} | mill-example-url: ${if (authorMode) s"file://${T.workspace}" else s"${Settings.projectUrl}/blob/main/"} | utest-github-url: https://github.com/com-lihaoyi/utest @@ -1966,6 +1968,7 @@ def exampleZips: T[Seq[PathRef]] = T { val example = examplePath.subRelativeTo(T.workspace) val exampleStr = millVersion() + "-" + example.segments.mkString("-") os.copy(examplePath, T.dest / exampleStr, createFolders = true) + os.write(T.dest / exampleStr / ".mill-version", millLastTag()) os.copy(bootstrapLauncher().path, T.dest / exampleStr / "mill") val zip = T.dest / s"$exampleStr.zip" os.proc("zip", "-r", zip, exampleStr).call(cwd = T.dest) diff --git a/docs/modules/ROOT/pages/Intro_to_Mill_for_Scala.adoc b/docs/modules/ROOT/pages/Intro_to_Mill_for_Scala.adoc index 16cd1e2d27e..b88f71d62f7 100644 --- a/docs/modules/ROOT/pages/Intro_to_Mill_for_Scala.adoc +++ b/docs/modules/ROOT/pages/Intro_to_Mill_for_Scala.adoc @@ -15,14 +15,6 @@ :page-aliases: index.adoc, Intro_to_Mill.adoc - -{mill-github-url}[Mill] is your shiny new Scala build tool! Mill aims for -simplicity by reusing concepts you are already familiar with, borrowing ideas -from modern tools like https://maven.apache.org/[Maven], https://gradle.org/[Gradle], -https://bazel.build/[Bazel] and https://www.scala-sbt.org/[SBT]. It lets you build -your projects in a way that's simple, fast, and predictable. - - {mill-github-url}[Mill] is your shiny new Scala build tool! Mill aims for simplicity by reusing concepts you are already familiar with, borrowing ideas from modern tools like https://maven.apache.org/[Maven], https://gradle.org/[Gradle], @@ -45,12 +37,6 @@ how Mill attempts to do better: - https://www.lihaoyi.com/post/SowhatswrongwithSBT.html[So, what's wrong with SBT?] - https://www.lihaoyi.com/post/MillBetterScalaBuilds.html[Mill: Better Scala Builds] -If you are using Mill, you will find the following book by the Author useful in -using Mill and its supporting libraries to the fullest: - -* https://handsonscala.com/[Hands-on Scala Programming] - - If you are using Mill, you will find the following book by the Author useful in using Mill and its supporting libraries to the fullest: diff --git a/docs/modules/ROOT/pages/Java_Module_Config.adoc b/docs/modules/ROOT/pages/Java_Module_Config.adoc index 8b8c24bfd47..471f4bc99aa 100644 --- a/docs/modules/ROOT/pages/Java_Module_Config.adoc +++ b/docs/modules/ROOT/pages/Java_Module_Config.adoc @@ -5,7 +5,7 @@ for `JavaModule`. Many of the APIs covered here are listed in the API documentation: -* {mill-doc-url}/api/latest/mill/scalalib/JavaModule.html[mill.scalalib.JavaModule] +* {mill-doc-url}/api/latest/mill/scalalib/JavaModule.html[mill.javaalib.JavaModule] == Compilation & Execution Flags diff --git a/docs/modules/ROOT/pages/Java_Web_Build_Examples.adoc b/docs/modules/ROOT/pages/Java_Web_Build_Examples.adoc index 603305b1bf5..efd13dfa985 100644 --- a/docs/modules/ROOT/pages/Java_Web_Build_Examples.adoc +++ b/docs/modules/ROOT/pages/Java_Web_Build_Examples.adoc @@ -1,4 +1,4 @@ -= Web Build Examples += Java Web Build Examples This page contains examples of using Mill as a build tool for web-applications. It covers setting up a basic backend server with a variety of server frameworks diff --git a/docs/modules/ROOT/pages/Web_Build_Examples.adoc b/docs/modules/ROOT/pages/Web_Build_Examples.adoc index 5f25c8cbb06..b377918b0b1 100644 --- a/docs/modules/ROOT/pages/Web_Build_Examples.adoc +++ b/docs/modules/ROOT/pages/Web_Build_Examples.adoc @@ -1,4 +1,4 @@ -= Web Build Examples += Scala Web Build Examples This page contains examples of using Mill as a build tool for web-applications. It covers setting up a basic backend server, Todo-MVC app, topics like cache diff --git a/example/basic/2-custom-build-logic/build.sc b/example/basic/2-custom-build-logic/build.sc index 659ecd1570a..5ec0473132c 100644 --- a/example/basic/2-custom-build-logic/build.sc +++ b/example/basic/2-custom-build-logic/build.sc @@ -42,7 +42,9 @@ Inputs: // Above, `def lineCount` is a new build target we define, which makes use of // `allSourceFiles` (an existing target) and is in-turn used in our override of -// `resources` (also an existing target). This generated file can then be +// `resources` (also an existing target). `os.read.lines` and `os.write `come +// from the https://github.com/com-lihaoyi/os-lib[OS-Lib] library, which is +// bundled with Mill. This generated file can then be // loaded and used at runtime, as see in the output of `mill run` // // While this is a toy example, it shows how easy it is to customize your Mill diff --git a/example/basic/4-builtin-commands/build.sc b/example/basic/4-builtin-commands/build.sc index d3e30027f87..9bd756c579a 100644 --- a/example/basic/4-builtin-commands/build.sc +++ b/example/basic/4-builtin-commands/build.sc @@ -115,7 +115,7 @@ Inputs: > mill show foo.allSourceFiles [ - ".../foo/src/Foo..." + ".../foo/src.../Foo..." ] */ diff --git a/example/basicjava/1-simple/src/Foo.java b/example/basicjava/1-simple/src/foo/Foo.java similarity index 100% rename from example/basicjava/1-simple/src/Foo.java rename to example/basicjava/1-simple/src/foo/Foo.java diff --git a/example/basicjava/1-simple/test/src/FooTest.java b/example/basicjava/1-simple/test/src/foo/FooTest.java similarity index 100% rename from example/basicjava/1-simple/test/src/FooTest.java rename to example/basicjava/1-simple/test/src/foo/FooTest.java diff --git a/example/basicjava/2-custom-build-logic/src/Foo.java b/example/basicjava/2-custom-build-logic/src/foo/Foo.java similarity index 100% rename from example/basicjava/2-custom-build-logic/src/Foo.java rename to example/basicjava/2-custom-build-logic/src/foo/Foo.java diff --git a/example/basicjava/2-custom-build-logic/test/src/FooTests.java b/example/basicjava/2-custom-build-logic/test/src/foo/FooTests.java similarity index 100% rename from example/basicjava/2-custom-build-logic/test/src/FooTests.java rename to example/basicjava/2-custom-build-logic/test/src/foo/FooTests.java diff --git a/example/basicjava/3-multi-module/bar/src/Bar.java b/example/basicjava/3-multi-module/bar/src/bar/Bar.java similarity index 100% rename from example/basicjava/3-multi-module/bar/src/Bar.java rename to example/basicjava/3-multi-module/bar/src/bar/Bar.java diff --git a/example/basicjava/3-multi-module/bar/test/src/BarTests.java b/example/basicjava/3-multi-module/bar/test/src/bar/BarTests.java similarity index 100% rename from example/basicjava/3-multi-module/bar/test/src/BarTests.java rename to example/basicjava/3-multi-module/bar/test/src/bar/BarTests.java diff --git a/example/basicjava/3-multi-module/build.sc b/example/basicjava/3-multi-module/build.sc index f499b835c2d..6f2a37adcf3 100644 --- a/example/basicjava/3-multi-module/build.sc +++ b/example/basicjava/3-multi-module/build.sc @@ -25,12 +25,14 @@ object bar extends MyModule{ // build.sc // foo/ // src/ -// Foo.java +// foo/ +// Foo.java // resources/ // ... // bar/ // src/ -// Bar.java +// bar/ +// Bar.java // resources/ // ... // out/ diff --git a/example/basicjava/3-multi-module/foo/src/Foo.java b/example/basicjava/3-multi-module/foo/src/foo/Foo.java similarity index 100% rename from example/basicjava/3-multi-module/foo/src/Foo.java rename to example/basicjava/3-multi-module/foo/src/foo/Foo.java diff --git a/example/basicjava/4-builtin-commands/bar/src/Bar.java b/example/basicjava/4-builtin-commands/bar/src/bar/Bar.java similarity index 100% rename from example/basicjava/4-builtin-commands/bar/src/Bar.java rename to example/basicjava/4-builtin-commands/bar/src/bar/Bar.java diff --git a/example/basicjava/4-builtin-commands/bar/test/src/BarTest.java b/example/basicjava/4-builtin-commands/bar/test/src/bar/BarTest.java similarity index 100% rename from example/basicjava/4-builtin-commands/bar/test/src/BarTest.java rename to example/basicjava/4-builtin-commands/bar/test/src/bar/BarTest.java diff --git a/example/basicjava/4-builtin-commands/foo/src/Foo.java b/example/basicjava/4-builtin-commands/foo/src/foo/Foo.java similarity index 100% rename from example/basicjava/4-builtin-commands/foo/src/Foo.java rename to example/basicjava/4-builtin-commands/foo/src/foo/Foo.java diff --git a/example/javabuilds/1-common-config/src/Foo.java b/example/javabuilds/1-common-config/src/foo/Foo.java similarity index 100% rename from example/javabuilds/1-common-config/src/Foo.java rename to example/javabuilds/1-common-config/src/foo/Foo.java diff --git a/example/javabuilds/2-custom-tasks/src/Foo.java b/example/javabuilds/2-custom-tasks/src/foo/Foo.java similarity index 100% rename from example/javabuilds/2-custom-tasks/src/Foo.java rename to example/javabuilds/2-custom-tasks/src/foo/Foo.java diff --git a/example/javabuilds/4-nested-modules/baz/src/Baz.java b/example/javabuilds/4-nested-modules/baz/src/baz/Baz.java similarity index 100% rename from example/javabuilds/4-nested-modules/baz/src/Baz.java rename to example/javabuilds/4-nested-modules/baz/src/baz/Baz.java diff --git a/example/javabuilds/4-nested-modules/foo/bar/src/Bar.java b/example/javabuilds/4-nested-modules/foo/bar/src/bar/Bar.java similarity index 100% rename from example/javabuilds/4-nested-modules/foo/bar/src/Bar.java rename to example/javabuilds/4-nested-modules/foo/bar/src/bar/Bar.java diff --git a/example/javabuilds/4-nested-modules/foo/qux/src/Qux.java b/example/javabuilds/4-nested-modules/foo/qux/src/qux/Qux.java similarity index 100% rename from example/javabuilds/4-nested-modules/foo/qux/src/Qux.java rename to example/javabuilds/4-nested-modules/foo/qux/src/qux/Qux.java diff --git a/example/javabuilds/4-nested-modules/foo/src/Foo.java b/example/javabuilds/4-nested-modules/foo/src/foo/Foo.java similarity index 100% rename from example/javabuilds/4-nested-modules/foo/src/Foo.java rename to example/javabuilds/4-nested-modules/foo/src/foo/Foo.java diff --git a/example/javabuilds/5-test-suite/bar/src/Bar.java b/example/javabuilds/5-test-suite/bar/src/bar/Bar.java similarity index 61% rename from example/javabuilds/5-test-suite/bar/src/Bar.java rename to example/javabuilds/5-test-suite/bar/src/bar/Bar.java index d457b8c1e97..45d4791612f 100644 --- a/example/javabuilds/5-test-suite/bar/src/Bar.java +++ b/example/javabuilds/5-test-suite/bar/src/bar/Bar.java @@ -2,10 +2,10 @@ public class Bar { public static void main(String[] args) { - System.out.println(hello()); + System.out.println(new Bar().hello()); } - public static String hello() { + public String hello() { return "Hello World"; } } \ No newline at end of file diff --git a/example/javabuilds/5-test-suite/bar/test/src/BarTests.java b/example/javabuilds/5-test-suite/bar/test/src/BarTests.java deleted file mode 100644 index 7a68f25fa6d..00000000000 --- a/example/javabuilds/5-test-suite/bar/test/src/BarTests.java +++ /dev/null @@ -1,19 +0,0 @@ -package bar; - -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class BarTests { - - @Test - public void hello() { - String result = Bar.hello(); - assertTrue(result.startsWith("Hello")); - } - - @Test - public void world() { - String result = Bar.hello(); - assertTrue(result.endsWith("World")); - } -} \ No newline at end of file diff --git a/example/javabuilds/5-test-suite/bar/test/src/bar/BarTests.java b/example/javabuilds/5-test-suite/bar/test/src/bar/BarTests.java new file mode 100644 index 00000000000..7b0d7d358ba --- /dev/null +++ b/example/javabuilds/5-test-suite/bar/test/src/bar/BarTests.java @@ -0,0 +1,32 @@ +package bar; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; +import org.junit.Test; + +public class BarTests { + + @Test + public void hello() { + String result = new Bar().hello(); + assertTrue(result.startsWith("Hello")); + } + + @Test + public void world() { + String result = new Bar().hello(); + assertTrue(result.endsWith("World")); + } + + @Test + public void testMockito() { + Bar mockBar = mock(Bar.class); + + when(mockBar.hello()).thenReturn("Hello Mockito World"); + + String result = mockBar.hello(); + + assertTrue(result.equals("Hello Mockito World")); + verify(mockBar).hello(); + } +} \ No newline at end of file diff --git a/example/javabuilds/5-test-suite/build.sc b/example/javabuilds/5-test-suite/build.sc index fdf858024b4..b39ba67d12c 100644 --- a/example/javabuilds/5-test-suite/build.sc +++ b/example/javabuilds/5-test-suite/build.sc @@ -4,20 +4,30 @@ import mill._, javalib._ object foo extends JavaModule { object test extends JavaTests { def testFramework = "com.novocode.junit.JUnitFramework" - def ivyDeps = T { - super.ivyDeps() ++ Agg(ivy"com.novocode:junit-interface:0.11") - } + def ivyDeps = Agg( + ivy"com.novocode:junit-interface:0.11", + ivy"org.mockito:mockito-core:4.6.1" + ) } } - +// This build defines a single module with a test suite, configured to use +// "JUnit" as the testing framework, along with Mockito. Test suites are themselves +// ``JavaModule``s, nested within the enclosing module, //// SNIPPET:BUILD2 object bar extends JavaModule { - object test extends JavaTests with TestModule.Junit4 + object test extends JavaTests with TestModule.Junit4{ + def ivyDeps = super.ivyDeps() ++ Agg( + ivy"org.mockito:mockito-core:4.6.1" + ) + } } //// SNIPPET:BUILD3 object qux extends JavaModule { - object test extends JavaTests with TestModule.Junit4 - object integration extends JavaTests with TestModule.Junit4 + object test extends JavaTests with TestModule.Junit5 + object integration extends JavaTests with TestModule.Junit5 } + +// This example also demonstrates using Junit 5 instead of Junit 4, +// with diff --git a/example/javabuilds/8-compat-modules/foo/src/main/java/Foo.java b/example/javabuilds/5-test-suite/foo/src/foo/Foo.java similarity index 61% rename from example/javabuilds/8-compat-modules/foo/src/main/java/Foo.java rename to example/javabuilds/5-test-suite/foo/src/foo/Foo.java index 2a23172eb1d..6495735bf03 100644 --- a/example/javabuilds/8-compat-modules/foo/src/main/java/Foo.java +++ b/example/javabuilds/5-test-suite/foo/src/foo/Foo.java @@ -2,10 +2,10 @@ public class Foo { public static void main(String[] args) { - System.out.println(hello()); + System.out.println(new Foo().hello()); } - public static String hello() { + public String hello() { return "Hello World"; } } \ No newline at end of file diff --git a/example/javabuilds/5-test-suite/foo/test/src/FooTests.java b/example/javabuilds/5-test-suite/foo/test/src/FooTests.java deleted file mode 100644 index f91561c1e7a..00000000000 --- a/example/javabuilds/5-test-suite/foo/test/src/FooTests.java +++ /dev/null @@ -1,19 +0,0 @@ -package foo; - -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class FooTests { - - @Test - public void hello() { - String result = Foo.hello(); - assertTrue(result.startsWith("Hello")); - } - - @Test - public void world() { - String result = Foo.hello(); - assertTrue(result.endsWith("World")); - } -} \ No newline at end of file diff --git a/example/javabuilds/5-test-suite/foo/test/src/foo/FooTests.java b/example/javabuilds/5-test-suite/foo/test/src/foo/FooTests.java new file mode 100644 index 00000000000..ec2c09987e7 --- /dev/null +++ b/example/javabuilds/5-test-suite/foo/test/src/foo/FooTests.java @@ -0,0 +1,32 @@ +package foo; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; +import org.junit.Test; + +public class FooTests { + + @Test + public void hello() { + String result = new Foo().hello(); + assertTrue(result.startsWith("Hello")); + } + + @Test + public void world() { + String result = new Foo().hello(); + assertTrue(result.endsWith("World")); + } + + @Test + public void testMockito() { + Foo mockFoo = mock(Foo.class); + + when(mockFoo.hello()).thenReturn("Hello Mockito World"); + + String result = mockFoo.hello(); + + assertTrue(result.equals("Hello Mockito World")); + verify(mockFoo).hello(); + } +} \ No newline at end of file diff --git a/example/javabuilds/5-test-suite/qux/integration/src/QuxIntegrationTests.java b/example/javabuilds/5-test-suite/qux/integration/src/qux/QuxIntegrationTests.java similarity index 63% rename from example/javabuilds/5-test-suite/qux/integration/src/QuxIntegrationTests.java rename to example/javabuilds/5-test-suite/qux/integration/src/qux/QuxIntegrationTests.java index c2854bcf960..a3d3cbc0798 100644 --- a/example/javabuilds/5-test-suite/qux/integration/src/QuxIntegrationTests.java +++ b/example/javabuilds/5-test-suite/qux/integration/src/qux/QuxIntegrationTests.java @@ -1,7 +1,7 @@ package qux; -import static org.junit.Assert.assertEquals; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; public class QuxIntegrationTests { diff --git a/example/javabuilds/5-test-suite/qux/src/Qux.java b/example/javabuilds/5-test-suite/qux/src/qux/Qux.java similarity index 100% rename from example/javabuilds/5-test-suite/qux/src/Qux.java rename to example/javabuilds/5-test-suite/qux/src/qux/Qux.java diff --git a/example/javabuilds/5-test-suite/qux/test/src/QuxTests.java b/example/javabuilds/5-test-suite/qux/test/src/qux/QuxTests.java similarity index 73% rename from example/javabuilds/5-test-suite/qux/test/src/QuxTests.java rename to example/javabuilds/5-test-suite/qux/test/src/qux/QuxTests.java index 7d0ac5ae12b..579a2eb55ab 100644 --- a/example/javabuilds/5-test-suite/qux/test/src/QuxTests.java +++ b/example/javabuilds/5-test-suite/qux/test/src/qux/QuxTests.java @@ -1,7 +1,7 @@ package qux; -import static org.junit.Assert.assertTrue; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; public class QuxTests { diff --git a/example/javabuilds/6-publish-module/foo/src/Foo.java b/example/javabuilds/6-publish-module/foo/src/foo/Foo.java similarity index 100% rename from example/javabuilds/6-publish-module/foo/src/Foo.java rename to example/javabuilds/6-publish-module/foo/src/foo/Foo.java diff --git a/example/javabuilds/8-compat-modules/bar/src/main/java/Bar.java b/example/javabuilds/8-compat-modules/bar/src/main/java/bar/Bar.java similarity index 100% rename from example/javabuilds/8-compat-modules/bar/src/main/java/Bar.java rename to example/javabuilds/8-compat-modules/bar/src/main/java/bar/Bar.java diff --git a/example/javabuilds/5-test-suite/foo/src/Foo.java b/example/javabuilds/8-compat-modules/foo/src/main/java/foo/Foo.java similarity index 100% rename from example/javabuilds/5-test-suite/foo/src/Foo.java rename to example/javabuilds/8-compat-modules/foo/src/main/java/foo/Foo.java diff --git a/example/javabuilds/8-compat-modules/foo/src/test/java/FooTests.java b/example/javabuilds/8-compat-modules/foo/src/test/java/foo/FooTests.java similarity index 100% rename from example/javabuilds/8-compat-modules/foo/src/test/java/FooTests.java rename to example/javabuilds/8-compat-modules/foo/src/test/java/foo/FooTests.java diff --git a/example/javabuilds/9-realistic/bar/src/Bar.java b/example/javabuilds/9-realistic/bar/src/bar/Bar.java similarity index 100% rename from example/javabuilds/9-realistic/bar/src/Bar.java rename to example/javabuilds/9-realistic/bar/src/bar/Bar.java diff --git a/example/javabuilds/9-realistic/bar/test/src/BarTests.java b/example/javabuilds/9-realistic/bar/test/src/bar/BarTests.java similarity index 100% rename from example/javabuilds/9-realistic/bar/test/src/BarTests.java rename to example/javabuilds/9-realistic/bar/test/src/bar/BarTests.java diff --git a/example/javabuilds/9-realistic/foo/src/Foo.java b/example/javabuilds/9-realistic/foo/src/foo/Foo.java similarity index 100% rename from example/javabuilds/9-realistic/foo/src/Foo.java rename to example/javabuilds/9-realistic/foo/src/foo/Foo.java diff --git a/example/javabuilds/9-realistic/foo/test/src/FooTests.java b/example/javabuilds/9-realistic/foo/test/src/foo/FooTests.java similarity index 100% rename from example/javabuilds/9-realistic/foo/test/src/FooTests.java rename to example/javabuilds/9-realistic/foo/test/src/foo/FooTests.java diff --git a/example/javabuilds/9-realistic/qux/src/Qux.java b/example/javabuilds/9-realistic/qux/src/qux/Qux.java similarity index 100% rename from example/javabuilds/9-realistic/qux/src/Qux.java rename to example/javabuilds/9-realistic/qux/src/qux/Qux.java diff --git a/example/javamodule/1-compilation-execution-flags/src/Foo.java b/example/javamodule/1-compilation-execution-flags/src/foo/Foo.java similarity index 100% rename from example/javamodule/1-compilation-execution-flags/src/Foo.java rename to example/javamodule/1-compilation-execution-flags/src/foo/Foo.java diff --git a/example/javamodule/10-assembly-config/foo/src/Foo.java b/example/javamodule/10-assembly-config/foo/src/foo/Foo.java similarity index 100% rename from example/javamodule/10-assembly-config/foo/src/Foo.java rename to example/javamodule/10-assembly-config/foo/src/foo/Foo.java diff --git a/example/javamodule/11-repository-config/foo/src/Foo.java b/example/javamodule/11-repository-config/foo/src/foo/Foo.java similarity index 100% rename from example/javamodule/11-repository-config/foo/src/Foo.java rename to example/javamodule/11-repository-config/foo/src/foo/Foo.java diff --git a/example/javamodule/2-ivy-deps/src/Foo.java b/example/javamodule/2-ivy-deps/src/foo/Foo.java similarity index 100% rename from example/javamodule/2-ivy-deps/src/Foo.java rename to example/javamodule/2-ivy-deps/src/foo/Foo.java diff --git a/example/javamodule/3-run-compile-deps/bar/src/Bar.java b/example/javamodule/3-run-compile-deps/bar/src/bar/Bar.java similarity index 100% rename from example/javamodule/3-run-compile-deps/bar/src/Bar.java rename to example/javamodule/3-run-compile-deps/bar/src/bar/Bar.java diff --git a/example/javamodule/3-run-compile-deps/foo/src/Foo.java b/example/javamodule/3-run-compile-deps/foo/src/foo/Foo.java similarity index 100% rename from example/javamodule/3-run-compile-deps/foo/src/Foo.java rename to example/javamodule/3-run-compile-deps/foo/src/foo/Foo.java diff --git a/example/javamodule/4-test-deps/baz/src/Baz.java b/example/javamodule/4-test-deps/baz/src/baz/Baz.java similarity index 100% rename from example/javamodule/4-test-deps/baz/src/Baz.java rename to example/javamodule/4-test-deps/baz/src/baz/Baz.java diff --git a/example/javamodule/4-test-deps/baz/test/src/BazTestUtils.java b/example/javamodule/4-test-deps/baz/test/src/baz/BazTestUtils.java similarity index 100% rename from example/javamodule/4-test-deps/baz/test/src/BazTestUtils.java rename to example/javamodule/4-test-deps/baz/test/src/baz/BazTestUtils.java diff --git a/example/javamodule/4-test-deps/baz/test/src/BazTests.java b/example/javamodule/4-test-deps/baz/test/src/baz/BazTests.java similarity index 54% rename from example/javamodule/4-test-deps/baz/test/src/BazTests.java rename to example/javamodule/4-test-deps/baz/test/src/baz/BazTests.java index ebc0284808a..68760f3ca86 100644 --- a/example/javamodule/4-test-deps/baz/test/src/BazTests.java +++ b/example/javamodule/4-test-deps/baz/test/src/baz/BazTests.java @@ -1,12 +1,14 @@ package baz; import org.junit.Test; +import com.google.common.math.IntMath; + import static org.junit.Assert.*; public class BazTests { @Test public void simple() { - BazTestUtils.bazAssertEquals(Baz.getValue(), 123); + BazTestUtils.bazAssertEquals(Baz.getValue(), IntMath.mean(122, 124)); } } \ No newline at end of file diff --git a/example/javamodule/4-test-deps/build.sc b/example/javamodule/4-test-deps/build.sc index 800f354676e..f63efc479a4 100644 --- a/example/javamodule/4-test-deps/build.sc +++ b/example/javamodule/4-test-deps/build.sc @@ -7,10 +7,13 @@ object qux extends JavaModule { object test extends JavaTests with TestModule.Junit4 { def moduleDeps = super.moduleDeps ++ Seq(baz.test) + def ivyDeps = super.ivyDeps() ++ Agg(ivy"com.google.guava:guava:33.2.1-jre") } } object baz extends JavaModule { - object test extends JavaTests with TestModule.Junit4 + object test extends JavaTests with TestModule.Junit4{ + def ivyDeps = super.ivyDeps() ++ Agg(ivy"com.google.guava:guava:33.2.1-jre") + } } diff --git a/example/javamodule/4-test-deps/qux/src/Qux.java b/example/javamodule/4-test-deps/qux/src/qux/Qux.java similarity index 100% rename from example/javamodule/4-test-deps/qux/src/Qux.java rename to example/javamodule/4-test-deps/qux/src/qux/Qux.java diff --git a/example/javamodule/4-test-deps/qux/test/src/QuxTests.java b/example/javamodule/4-test-deps/qux/test/src/QuxTests.java deleted file mode 100644 index 471d2e1208a..00000000000 --- a/example/javamodule/4-test-deps/qux/test/src/QuxTests.java +++ /dev/null @@ -1,11 +0,0 @@ -package qux; - -import org.junit.Test; - -public class QuxTests { - - @Test - public void simple() { - baz.BazTestUtils.bazAssertEquals("xyz", Qux.getValue()); - } -} \ No newline at end of file diff --git a/example/javamodule/4-test-deps/qux/test/src/qux/QuxTests.java b/example/javamodule/4-test-deps/qux/test/src/qux/QuxTests.java new file mode 100644 index 00000000000..3aecbb5ec48 --- /dev/null +++ b/example/javamodule/4-test-deps/qux/test/src/qux/QuxTests.java @@ -0,0 +1,12 @@ +package qux; + +import org.junit.Test; +import com.google.common.base.Ascii; + +public class QuxTests { + + @Test + public void simple() { + baz.BazTestUtils.bazAssertEquals(Ascii.toLowerCase("XYZ"), Qux.getValue()); + } +} \ No newline at end of file diff --git a/example/javamodule/6-docjar/foo/src/Foo.java b/example/javamodule/6-docjar/foo/src/foo/Foo.java similarity index 100% rename from example/javamodule/6-docjar/foo/src/Foo.java rename to example/javamodule/6-docjar/foo/src/foo/Foo.java diff --git a/example/javamodule/7-unmanaged-jars/src/Foo.java b/example/javamodule/7-unmanaged-jars/src/foo/Foo.java similarity index 100% rename from example/javamodule/7-unmanaged-jars/src/Foo.java rename to example/javamodule/7-unmanaged-jars/src/foo/Foo.java diff --git a/example/javamodule/8-main-class/src/Bar.java b/example/javamodule/8-main-class/src/foo/Bar.java similarity index 100% rename from example/javamodule/8-main-class/src/Bar.java rename to example/javamodule/8-main-class/src/foo/Bar.java diff --git a/example/javamodule/8-main-class/src/Foo.java b/example/javamodule/8-main-class/src/foo/Foo.java similarity index 100% rename from example/javamodule/8-main-class/src/Foo.java rename to example/javamodule/8-main-class/src/foo/Foo.java diff --git a/example/javamodule/8-main-class/src/Qux.java b/example/javamodule/8-main-class/src/foo/Qux.java similarity index 100% rename from example/javamodule/8-main-class/src/Qux.java rename to example/javamodule/8-main-class/src/foo/Qux.java diff --git a/example/javamodule/9-downloading-non-maven-jars/src/Foo.java b/example/javamodule/9-downloading-non-maven-jars/src/foo/Foo.java similarity index 100% rename from example/javamodule/9-downloading-non-maven-jars/src/Foo.java rename to example/javamodule/9-downloading-non-maven-jars/src/foo/Foo.java diff --git a/example/javaweb/1-hello-jetty/build.sc b/example/javaweb/1-hello-jetty/build.sc index 1a27e11cbbb..956ad33e0b3 100644 --- a/example/javaweb/1-hello-jetty/build.sc +++ b/example/javaweb/1-hello-jetty/build.sc @@ -6,7 +6,7 @@ object hello extends RootModule with JavaModule { ivy"javax.servlet:javax.servlet-api:4.0.1" ) - object test extends JavaModuleTests with TestModule.Junit4 + object test extends JavaTests with TestModule.Junit4 } // This example demonstrates how to set up a simple Jetty webserver, diff --git a/example/javaweb/1-hello-jetty/src/HelloJetty.java b/example/javaweb/1-hello-jetty/src/com/example/HelloJetty.java similarity index 97% rename from example/javaweb/1-hello-jetty/src/HelloJetty.java rename to example/javaweb/1-hello-jetty/src/com/example/HelloJetty.java index e4bd2f7c539..84b093762b7 100644 --- a/example/javaweb/1-hello-jetty/src/HelloJetty.java +++ b/example/javaweb/1-hello-jetty/src/com/example/HelloJetty.java @@ -1,3 +1,4 @@ +package com.example; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; diff --git a/example/javaweb/1-hello-jetty/test/src/HelloJettyTest.java b/example/javaweb/1-hello-jetty/test/src/com/example/HelloJettyTest.java similarity index 98% rename from example/javaweb/1-hello-jetty/test/src/HelloJettyTest.java rename to example/javaweb/1-hello-jetty/test/src/com/example/HelloJettyTest.java index 61a57713ebc..31a19c23100 100644 --- a/example/javaweb/1-hello-jetty/test/src/HelloJettyTest.java +++ b/example/javaweb/1-hello-jetty/test/src/com/example/HelloJettyTest.java @@ -1,3 +1,4 @@ +package com.example; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.HandlerList; diff --git a/example/javaweb/2-hello-spring-boot/build.sc b/example/javaweb/2-hello-spring-boot/build.sc index 7f4cbfa1f9d..ba9649e1286 100644 --- a/example/javaweb/2-hello-spring-boot/build.sc +++ b/example/javaweb/2-hello-spring-boot/build.sc @@ -6,7 +6,7 @@ object hello extends RootModule with JavaModule { ivy"org.springframework.boot:spring-boot-starter-actuator:2.5.6" ) - object test extends JavaModuleTests with TestModule.Junit5 { + object test extends JavaTests with TestModule.Junit5 { def ivyDeps = super.ivyDeps() ++ Agg( ivy"org.springframework.boot:spring-boot-starter-test:2.5.6" ) diff --git a/example/javaweb/2-hello-spring-boot/src/HelloSpringBoot.java b/example/javaweb/2-hello-spring-boot/src/com/example/HelloSpringBoot.java similarity index 100% rename from example/javaweb/2-hello-spring-boot/src/HelloSpringBoot.java rename to example/javaweb/2-hello-spring-boot/src/com/example/HelloSpringBoot.java diff --git a/example/javaweb/2-hello-spring-boot/test/src/HelloSpringBootTest.java b/example/javaweb/2-hello-spring-boot/test/src/com/example/HelloSpringBootTest.java similarity index 100% rename from example/javaweb/2-hello-spring-boot/test/src/HelloSpringBootTest.java rename to example/javaweb/2-hello-spring-boot/test/src/com/example/HelloSpringBootTest.java diff --git a/example/javaweb/3-todo-spring-boot/build.sc b/example/javaweb/3-todo-spring-boot/build.sc index 5c841269c00..44dddbd428c 100644 --- a/example/javaweb/3-todo-spring-boot/build.sc +++ b/example/javaweb/3-todo-spring-boot/build.sc @@ -13,14 +13,30 @@ object hello extends RootModule with JavaModule { ivy"org.webjars.npm:todomvc-common:1.0.5", ivy"org.webjars.npm:todomvc-app-css:2.4.1", - ivy"com.h2database:h2:2.3.230" + ) - object test extends JavaModuleTests with TestModule.Junit5 { + trait HelloTests extends JavaTests with TestModule.Junit5{ + def mainClass = Some("com.example.TodomvcApplication") def ivyDeps = super.ivyDeps() ++ Agg( ivy"org.springframework.boot:spring-boot-starter-test:2.5.6" ) } + + object test extends HelloTests{ + def ivyDeps = super.ivyDeps() ++ Agg( + ivy"com.h2database:h2:2.3.230", + ) + } + + object integration extends HelloTests { + def ivyDeps = super.ivyDeps() ++ Agg( + ivy"org.testcontainers:testcontainers:1.18.0", + ivy"org.testcontainers:junit-jupiter:1.18.0", + ivy"org.testcontainers:postgresql:1.18.0", + ivy"org.postgresql:postgresql:42.6.0", + ) + } } // This is a larger example using Spring Boot, implementing the well known @@ -30,15 +46,21 @@ object hello extends RootModule with JavaModule { // * Serving HTML templates using Thymeleaf // * Serving static Javascript and CSS using Webjars // * Querying a SQL database using JPA and H2 +// * Unit testing using a H2 in-memory database +// * Integration testing using Testcontainers Postgres in Docker /** Usage > mill test -...com.example.TodomvcApplicationTests#homePageLoads() finished... -...com.example.TodomvcApplicationTests#addNewTodoItem() finished... +...com.example.TodomvcTests#homePageLoads() finished... +...com.example.TodomvcTests#addNewTodoItem() finished... + +> mill integration +...com.example.TodomvcIntegrationTests#homePageLoads() finished... +...com.example.TodomvcIntegrationTests#addNewTodoItem() finished... -> mill runBackground +> mill test.runBackground > curl http://localhost:8087 ...

todos

... diff --git a/example/javaweb/3-todo-spring-boot/integration/resources/application.properties b/example/javaweb/3-todo-spring-boot/integration/resources/application.properties new file mode 100644 index 00000000000..7db1b07b8ac --- /dev/null +++ b/example/javaweb/3-todo-spring-boot/integration/resources/application.properties @@ -0,0 +1,3 @@ +spring.mvc.hiddenmethod.filter.enabled=true +spring.jpa.hibernate.ddl-auto=update +spring.datasource.driver-class-name=org.postgresql.Driver \ No newline at end of file diff --git a/example/javaweb/3-todo-spring-boot/integration/src/com/example/TodomvcIntegrationTests.java b/example/javaweb/3-todo-spring-boot/integration/src/com/example/TodomvcIntegrationTests.java new file mode 100644 index 00000000000..d9ff593454e --- /dev/null +++ b/example/javaweb/3-todo-spring-boot/integration/src/com/example/TodomvcIntegrationTests.java @@ -0,0 +1,69 @@ +package com.example; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import static org.assertj.core.api.Assertions.assertThat; + +@Testcontainers +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class TodomvcIntegrationTests { + + @Container + public static PostgreSQLContainer postgresContainer = new PostgreSQLContainer<>("postgres:latest") + .withDatabaseName("test") + .withUsername("test") + .withPassword("test"); + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @DynamicPropertySource + static void postgresProperties(DynamicPropertyRegistry registry) { + registry.add("spring.datasource.url", postgresContainer::getJdbcUrl); + registry.add("spring.datasource.username", postgresContainer::getUsername); + registry.add("spring.datasource.password", postgresContainer::getPassword); + } + + @Test + void homePageLoads() { + ResponseEntity response = this.restTemplate.getForEntity("http://localhost:" + port + "/", String.class); + assertThat(response.getStatusCode().is2xxSuccessful()).isTrue(); + assertThat(response.getBody()).contains("

todos

"); + } + + @Test + void addNewTodoItem() { + // Set up headers and form data for the POST request + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + String newTodo = "title=Test+Todo"; + HttpEntity entity = new HttpEntity<>(newTodo, headers); + + // Send the POST request to add a new todo item + ResponseEntity postResponse = this.restTemplate.exchange("http://localhost:" + port + "/", HttpMethod.POST, entity, String.class); + assertThat(postResponse.getStatusCode().is3xxRedirection()).isTrue(); + + // Send a GET request to verify the new todo item was added + ResponseEntity getResponse = this.restTemplate.getForEntity("http://localhost:" + port + "/", String.class); + assertThat(getResponse.getStatusCode().is2xxSuccessful()).isTrue(); + assertThat(getResponse.getBody()).contains("Test Todo"); + } +} diff --git a/example/javaweb/3-todo-spring-boot/src/TodomvcApplication.java b/example/javaweb/3-todo-spring-boot/src/com/example/TodomvcApplication.java similarity index 100% rename from example/javaweb/3-todo-spring-boot/src/TodomvcApplication.java rename to example/javaweb/3-todo-spring-boot/src/com/example/TodomvcApplication.java diff --git a/example/javaweb/3-todo-spring-boot/src/todoitem/TodoItem.java b/example/javaweb/3-todo-spring-boot/src/com/example/todoitem/TodoItem.java similarity index 100% rename from example/javaweb/3-todo-spring-boot/src/todoitem/TodoItem.java rename to example/javaweb/3-todo-spring-boot/src/com/example/todoitem/TodoItem.java diff --git a/example/javaweb/3-todo-spring-boot/src/todoitem/TodoItemNotFoundException.java b/example/javaweb/3-todo-spring-boot/src/com/example/todoitem/TodoItemNotFoundException.java similarity index 100% rename from example/javaweb/3-todo-spring-boot/src/todoitem/TodoItemNotFoundException.java rename to example/javaweb/3-todo-spring-boot/src/com/example/todoitem/TodoItemNotFoundException.java diff --git a/example/javaweb/3-todo-spring-boot/src/todoitem/TodoItemRepository.java b/example/javaweb/3-todo-spring-boot/src/com/example/todoitem/TodoItemRepository.java similarity index 100% rename from example/javaweb/3-todo-spring-boot/src/todoitem/TodoItemRepository.java rename to example/javaweb/3-todo-spring-boot/src/com/example/todoitem/TodoItemRepository.java diff --git a/example/javaweb/3-todo-spring-boot/src/todoitem/web/TodoItemController.java b/example/javaweb/3-todo-spring-boot/src/com/example/todoitem/web/TodoItemController.java similarity index 100% rename from example/javaweb/3-todo-spring-boot/src/todoitem/web/TodoItemController.java rename to example/javaweb/3-todo-spring-boot/src/com/example/todoitem/web/TodoItemController.java diff --git a/example/javaweb/3-todo-spring-boot/src/todoitem/web/TodoItemFormData.java b/example/javaweb/3-todo-spring-boot/src/com/example/todoitem/web/TodoItemFormData.java similarity index 100% rename from example/javaweb/3-todo-spring-boot/src/todoitem/web/TodoItemFormData.java rename to example/javaweb/3-todo-spring-boot/src/com/example/todoitem/web/TodoItemFormData.java diff --git a/example/javaweb/3-todo-spring-boot/resources/application.properties b/example/javaweb/3-todo-spring-boot/test/resources/application.properties similarity index 100% rename from example/javaweb/3-todo-spring-boot/resources/application.properties rename to example/javaweb/3-todo-spring-boot/test/resources/application.properties diff --git a/example/javaweb/3-todo-spring-boot/test/src/TodomvcApplicationTests.java b/example/javaweb/3-todo-spring-boot/test/src/com/example/TodomvcTests.java similarity index 98% rename from example/javaweb/3-todo-spring-boot/test/src/TodomvcApplicationTests.java rename to example/javaweb/3-todo-spring-boot/test/src/com/example/TodomvcTests.java index 24c9e161a55..dfaa678cf04 100644 --- a/example/javaweb/3-todo-spring-boot/test/src/TodomvcApplicationTests.java +++ b/example/javaweb/3-todo-spring-boot/test/src/com/example/TodomvcTests.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class TodomvcApplicationTests { +class TodomvcTests { @LocalServerPort private int port; diff --git a/example/scalabuilds/5-test-suite/build.sc b/example/scalabuilds/5-test-suite/build.sc index b818cf32856..d06104cedf5 100644 --- a/example/scalabuilds/5-test-suite/build.sc +++ b/example/scalabuilds/5-test-suite/build.sc @@ -8,10 +8,12 @@ object foo extends ScalaModule { def testFramework = "utest.runner.Framework" } } -//// SNIPPET:END + // This build defines a single module with a test suite, configured to use // "uTest" as the testing framework. Test suites are themselves ``ScalaModule``s, -// nested within the enclosing module, and have all the normal tasks like +// nested within the enclosing module, +//// SNIPPET:END +// and have all the normal tasks like // `foo.test.compile` available to run, but with an additional `.test` task // that runs the tests. You can also run the test suite directly, in which case // it will run the `.test` task as the default task for that module. @@ -103,15 +105,15 @@ object qux extends ScalaModule { /** Usage > mill qux.test -...qux.QuxTests.hello ... -...qux.QuxTests.world ... +...qux.QuxTests...hello... +...qux.QuxTests...world... > mill qux.integration -...qux.QuxIntegrationTests.helloworld ... +...qux.QuxIntegrationTests...helloworld... > mill qux.{test,integration} -...qux.QuxTests.hello ... -...qux.QuxTests.world ... -...qux.QuxIntegrationTests.helloworld ... +...qux.QuxTests...hello... +...qux.QuxTests...world... +...qux.QuxIntegrationTests...helloworld... */ \ No newline at end of file diff --git a/example/scalamodule/9-downloading-non-maven-jars/build.sc b/example/scalamodule/9-downloading-non-maven-jars/build.sc index c069d836be0..cf3e5154602 100644 --- a/example/scalamodule/9-downloading-non-maven-jars/build.sc +++ b/example/scalamodule/9-downloading-non-maven-jars/build.sc @@ -18,6 +18,8 @@ object foo extends RootModule with ScalaModule { // You can also override `unmanagedClasspath` to point it at jars that you want to // download from arbitrary URLs. Note that targets like `unmanagedClasspath` are // cached, so your jar is downloaded only once and re-used indefinitely after that. +// `requests.get` comes from the https://github.com/com-lihaoyi/requests-scala[Requests-Scala] +// library, which is bundled with Mill /** Usage diff --git a/example/tasks/2-primary-tasks/build.sc b/example/tasks/2-primary-tasks/build.sc index b18e4254496..fb21e93a23d 100644 --- a/example/tasks/2-primary-tasks/build.sc +++ b/example/tasks/2-primary-tasks/build.sc @@ -172,7 +172,7 @@ def resources = T.source { millSourcePath / "resources" } > ./mill jar # Cached from earlier -> printf "\n" >> src/Foo.java # Add a newline to the end of Foo.java +> printf "\n" >> src/foo/Foo.java # Add a newline to the end of Foo.java > ./mill jar # Classfiles recompiled but output unchanged, jar was not rebuilt Generating classfiles diff --git a/example/tasks/2-primary-tasks/src/Foo.java b/example/tasks/2-primary-tasks/src/foo/Foo.java similarity index 100% rename from example/tasks/2-primary-tasks/src/Foo.java rename to example/tasks/2-primary-tasks/src/foo/Foo.java diff --git a/example/thirdparty/jimfs/build.sc b/example/thirdparty/jimfs/build.sc index 440aafab7ca..d8b5543532d 100644 --- a/example/thirdparty/jimfs/build.sc +++ b/example/thirdparty/jimfs/build.sc @@ -1,4 +1,4 @@ -import mill._, scalalib._, publish._ +import mill._, javalib._, publish._ def sharedCompileIvyDeps = T{ Agg(