|
| 1 | += Migrating From Maven to Mill |
| 2 | +:page-aliases: Migrating_A_Maven_Build_to_Mill.adoc |
| 3 | +:icons: font |
| 4 | + |
| 5 | +include::partial$gtag-config.adoc[] |
| 6 | + |
| 7 | +The Mill `init` command can be used to convert a Maven build to Mill. This has |
| 8 | +xref:#limitations[limitations] and is not intended to reliably migrate 100% of |
| 9 | +Maven builds out there in the wild, but is instead meant to provide the basic |
| 10 | +scaffolding of a Mill build for you to further refine and update manually. |
| 11 | + |
| 12 | +Each Maven module with a `pom.xml` is converted to a Mill `build.mill`/`package.mill` |
| 13 | +file containing a top-level `MavenModule`. A nested `test` module is defined if both: |
| 14 | + |
| 15 | +* `src/test` exists |
| 16 | +* a supported xref:javalib/testing.adoc[test framework] is detected (for a _tests only_ |
| 17 | +module with test sources in `src/main/java`) |
| 18 | +
|
| 19 | +
|
| 20 | +Again, note that `mill init` importing Maven builds is best effort. |
| 21 | +This means that while small projects can be expected to complete without issue: |
| 22 | + |
| 23 | +include::partial$example/javalib/migrating/1-maven-complete.adoc[] |
| 24 | + |
| 25 | +More larger projects often require some manual tweaking in order to work: |
| 26 | + |
| 27 | +include::partial$example/javalib/migrating/2-maven-incomplete.adoc[] |
| 28 | + |
| 29 | +Nevertheless, even for larger builds `mill init` automates most of the tedious |
| 30 | +busy-work of writing `build.mill`/`package.mill` files, and makes it much quicker |
| 31 | +to get a working Mill build for any existing Maven project. |
| 32 | + |
| 33 | + |
| 34 | +== Capabilities |
| 35 | + |
| 36 | +The conversion |
| 37 | + |
| 38 | +* handles deeply nested modules |
| 39 | +* captures project metadata |
| 40 | +* configures dependencies for scopes: |
| 41 | +** compile |
| 42 | +** provided |
| 43 | +** runtime |
| 44 | +** test |
| 45 | +* configures testing frameworks: |
| 46 | +** JUnit 4 |
| 47 | +** JUnit 5 |
| 48 | +** TestNG |
| 49 | +* configures multiple, compile and test, resource directories |
| 50 | + |
| 51 | +=== Command line arguments |
| 52 | +.name of generated base module trait defining project metadata settings |
| 53 | +[source,sh] |
| 54 | +---- |
| 55 | +./mill init --base-module MyModule |
| 56 | +---- |
| 57 | +.name of generated nested test module (defaults to `test`) |
| 58 | +[source,sh] |
| 59 | +---- |
| 60 | +./mill init --test-module test |
| 61 | +---- |
| 62 | +.name of generated companion object defining constants for dependencies |
| 63 | +[source,sh] |
| 64 | +---- |
| 65 | +./mill init --deps-object Deps |
| 66 | +---- |
| 67 | +.capture properties defined in `pom.xml` for publishing |
| 68 | +[source,sh] |
| 69 | +---- |
| 70 | +./mill init --publish-properties |
| 71 | +---- |
| 72 | +.merge build files generated for a multi-module build |
| 73 | +[source,sh] |
| 74 | +---- |
| 75 | +./mill init --merge |
| 76 | +---- |
| 77 | + |
| 78 | +.use cache for Maven repository system |
| 79 | +[source,sh] |
| 80 | +---- |
| 81 | +./mill init --cache-repository |
| 82 | +---- |
| 83 | +.process Maven plugin executions and configurations |
| 84 | +[source,sh] |
| 85 | +---- |
| 86 | +./mill init --process-plugins |
| 87 | +---- |
| 88 | + |
| 89 | +=== Verified projects |
| 90 | + |
| 91 | +The conversion has been tested with the following projects: |
| 92 | + |
| 93 | +* https://github.com/fusesource/jansi/archive/refs/tags/jansi-2.4.1.zip[jansi] |
| 94 | +[source,sh] |
| 95 | +---- |
| 96 | +./mill init --base-module JansiModule --deps-object Deps --cache-repository --process-plugins |
| 97 | +---- |
| 98 | + |
| 99 | +* https://github.com/davidmoten/geo/archive/refs/tags/0.8.1.zip[geo] (multi-module build) |
| 100 | +[source,sh] |
| 101 | +---- |
| 102 | +./mill init --base-module GeoModule --deps-object Deps --merge --cache-repository --process-plugins |
| 103 | +---- |
| 104 | + |
| 105 | +Post `init`, the following tasks were executed successfully: |
| 106 | + |
| 107 | +* `compile` |
| 108 | +* `test` |
| 109 | +* `publishLocal` |
| 110 | + |
| 111 | +[#limitations] |
| 112 | +== Limitations |
| 113 | + |
| 114 | +The conversion does not support |
| 115 | + |
| 116 | +* build extensions |
| 117 | +* build profiles |
| 118 | +* non-Java (native) sources |
| 119 | + |
| 120 | +Maven plugin support is limited to |
| 121 | + |
| 122 | +* https://maven.apache.org/plugins/maven-compiler-plugin/[maven-compiler-plugin] |
| 123 | + |
| 124 | +[TIP] |
| 125 | +==== |
| 126 | +These limitations can be overcome by: |
| 127 | +
|
| 128 | +* configuring equivalent Mill xref:extending/contrib-plugins.adoc[contrib] |
| 129 | + or xref:extending/thirdparty-plugins.adoc[third party] plugins |
| 130 | +* defining custom xref:extending/writing-plugins.adoc[plugins] |
| 131 | +* defining custom xref:fundamentals/tasks.adoc[tasks] |
| 132 | +* defining custom xref:fundamentals/cross-builds.adoc[cross modules] |
| 133 | +==== |
| 134 | + |
| 135 | +== FAQ |
| 136 | + |
| 137 | +.How to fix compilation errors in generated build files? |
| 138 | + |
| 139 | +This could happen if a module and task name collision occurs. Either rename the module or enclose the name in backticks. |
| 140 | + |
| 141 | + |
| 142 | +.How to fix JPMS `module not found` compilation errors? |
| 143 | + |
| 144 | +Set https://github.com/tfesenko/Java-Modules-JPMS-CheatSheet#how-to-export-or-open-a-package[additional command line options] |
| 145 | +for dependencies. |
| 146 | + |
| 147 | + |
| 148 | +.How to fix test compilation errors? |
| 149 | + |
| 150 | +* The test framework configured may be for an unsupported version; try upgrading the |
| 151 | + corresponding dependencies. |
| 152 | +* Mill does not add `provided` dependencies to the transitive dependencies of the nested |
| 153 | + test module; specify the dependencies again, in one of `ivyDeps`, `compileIvyDeps`, `runIvyDeps`, in the test module. |
| 154 | + |
| 155 | + |
0 commit comments