-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for 'mill init' from existing Gradle project #4363
Changes from 7 commits
a71cecb
49386ba
4cf060c
73c31e2
8e448da
c4a0549
a01f852
7b08e2e
96ffc8a
723653e
8133658
6539731
491ef5b
688f27a
c151767
c277e71
df20659
dbddfbd
8d6aa36
0519f16
b03ae2d
c136f18
ce4a916
3285006
d5c68ee
f1b72a9
00017ed
2ad6263
0cd3a69
3def3e4
5942db5
46654ce
35bcc35
da1a56c
c61fce9
2cf079c
632be2a
ff8747b
466a0bb
d8e7be4
afca05e
428310e
3b863dd
25a427e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,121 @@ | ||||||||||||||||||||||||
= Migrating From Gradle to Mill | ||||||||||||||||||||||||
:page-aliases: Migrating_A_Gradle_Build_to_Mill.adoc | ||||||||||||||||||||||||
:icons: font | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
include::partial$gtag-config.adoc[] | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
The Mill `init` command can be used to convert a Gradle build to Mill. This has | ||||||||||||||||||||||||
xref:#limitations[limitations] and is not intended to reliably migrate 100% of | ||||||||||||||||||||||||
Gradle builds out there in the wild, but is instead meant to provide the basic | ||||||||||||||||||||||||
scaffolding of a Mill build for you to further refine and update manually. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Each Gradle project in a build tree is converted to a Mill module. | ||||||||||||||||||||||||
A nested `test` module is defined, if `src/test` exists, and is configured with a supported xref:javalib/testing.adoc[test framework], if found. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Again, note that `mill init` imports a Gradle build on a best-effort basis. | ||||||||||||||||||||||||
This means that while simple projects can be expected to complete without issue: | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
include::partial$example/javalib/migrating/3-gradle-complete.adoc[] | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Projects with a complex build often require some manual tweaking in order to work: | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
include::partial$example/javalib/migrating/4-gradle-incomplete.adoc[] | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
== Capabilities | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
The conversion | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* handles deeply nested modules | ||||||||||||||||||||||||
* captures publish settings | ||||||||||||||||||||||||
* configures dependencies for https://docs.gradle.org/current/userguide/dependency_configurations.html#sub:what-are-dependency-configurations[configurations] | ||||||||||||||||||||||||
** implementation / api | ||||||||||||||||||||||||
** compileOnly / compileOnlyApi | ||||||||||||||||||||||||
** runtimeOnly | ||||||||||||||||||||||||
** testImplementation | ||||||||||||||||||||||||
** testCompileOnly | ||||||||||||||||||||||||
* configures testing frameworks | ||||||||||||||||||||||||
** JUnit 4 | ||||||||||||||||||||||||
** JUnit 5 | ||||||||||||||||||||||||
** TestNG | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
[#arguments] | ||||||||||||||||||||||||
=== Command line arguments | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
The conversion and it's output (the generated Mill build files) can be customized using | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
* `--base-module` (`-b`): name of generated base module trait defining shared settings | ||||||||||||||||||||||||
[source,sh] | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
./mill init --base-module MyModule | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example how to keep the source block in the list item. https://docs.asciidoctor.org/asciidoc/latest/lists/continuation/#list-continuation
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
ajaychandran marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
* `--base-project` (`-g`): name of Gradle project to extract settings for `--base-module` | ||||||||||||||||||||||||
[source,sh] | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
./mill init --base-module MyModule --base-project lib | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
NOTE: If not specified, a project will be selected arbitrarily. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* `--jvm-id` (`-j`): version of xref:fundamentals/configuring-jvm-versions.adoc[custom JVM] to configure in `--base-module` | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "JVM ID" is not a widely know term. From the code I get it that it can include the distribution and the version, so you might've forgotten to update the docs here:
Suggested change
|
||||||||||||||||||||||||
[source,sh] | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
./mill init --base-module MyModule --jvm-id 17 | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* `--test-module` (`-t`): name of generated nested test module (defaults to `test`) | ||||||||||||||||||||||||
[source,sh] | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
./mill init --test-module test | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* `--deps-object` (`-d`): name of generated companion object defining dependency constants | ||||||||||||||||||||||||
[source,sh] | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
./mill init --deps-object Deps | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* `--merge` (`-m`): merge build files generated for a multi-module build | ||||||||||||||||||||||||
[source,sh] | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
./mill init --merge | ||||||||||||||||||||||||
---- | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
TIP: You can run `mill init` multiple times. It is recommended to run it first without any options. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
[#limitations] | ||||||||||||||||||||||||
== Limitations | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
The conversion does not support | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* custom dependency configurations | ||||||||||||||||||||||||
* custom tasks | ||||||||||||||||||||||||
* non-Java sources | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Gradle plugin support is limited to | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* https://docs.gradle.org/current/userguide/java_plugin.html[java] | ||||||||||||||||||||||||
* https://docs.gradle.org/current/userguide/publishing_maven.html[maven-publish] | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
[TIP] | ||||||||||||||||||||||||
==== | ||||||||||||||||||||||||
These limitations can be overcome by: | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* configuring equivalent Mill xref:extending/contrib-plugins.adoc[contrib] | ||||||||||||||||||||||||
or xref:extending/thirdparty-plugins.adoc[third party] plugins | ||||||||||||||||||||||||
* defining custom xref:extending/writing-plugins.adoc[plugins] | ||||||||||||||||||||||||
* defining custom xref:fundamentals/tasks.adoc[tasks] | ||||||||||||||||||||||||
* defining custom xref:fundamentals/cross-builds.adoc[cross modules] | ||||||||||||||||||||||||
==== | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
== FAQ | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
How to fix `java.lang.UnsupportedClassVersionError` error thrown by `mill init`? | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Select a https://docs.gradle.org/current/userguide/compatibility.html#java_runtime[Java Runtime] compatible with the version of Gradle used and pass it using the `--jvm-id` xref:arguments[argument]. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
How to fix test compilation errors? | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
* The test framework configured may be for an unsupported version; try upgrading the | ||||||||||||||||||||||||
corresponding dependencies. | ||||||||||||||||||||||||
* Mill does not add `compileIvyDeps` dependencies to the transitive dependencies of the nested | ||||||||||||||||||||||||
test module; specify the dependencies again, in `ivyDeps` or `runIvyDeps`. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,14 +10,10 @@ Maven builds out there in the wild, but is instead meant to provide the basic | |||||
scaffolding of a Mill build for you to further refine and update manually. | ||||||
|
||||||
Each Maven module with a `pom.xml` is converted to a Mill `build.mill`/`package.mill` | ||||||
file containing a top-level `MavenModule`. A nested `test` module is defined if both: | ||||||
file containing a top-level `MavenModule`. | ||||||
A nested `test` module is defined, if `src/test` exists, and is configured with a supported xref:javalib/testing.adoc[test framework], if found. | ||||||
|
||||||
* `src/test` exists | ||||||
* a supported xref:javalib/testing.adoc[test framework] is detected (for a _tests only_ | ||||||
module with test sources in `src/main/java`) | ||||||
|
||||||
|
||||||
Again, note that `mill init` importing Maven builds is best effort. | ||||||
Again, note that `mill init` importing Maven builds is best-effort. | ||||||
This means that while small projects can be expected to complete without issue: | ||||||
|
||||||
include::partial$example/javalib/migrating/1-maven-complete.adoc[] | ||||||
|
@@ -36,56 +32,72 @@ to get a working Mill build for any existing Maven project. | |||||
The conversion | ||||||
|
||||||
* handles deeply nested modules | ||||||
* captures project metadata | ||||||
* configures dependencies for scopes: | ||||||
* captures publish settings | ||||||
* configures dependencies for scopes | ||||||
** compile | ||||||
** provided | ||||||
** runtime | ||||||
** test | ||||||
* configures testing frameworks: | ||||||
* configures testing frameworks | ||||||
** JUnit 4 | ||||||
** JUnit 5 | ||||||
** TestNG | ||||||
* configures multiple, compile and test, resource directories | ||||||
|
||||||
=== Command line arguments | ||||||
.name of generated base module trait defining project metadata settings | ||||||
|
||||||
The conversion and it's output (the generated Mill build files) can be customized using | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
* `--base-module` (`-b`): name of generated base module trait defining shared settings | ||||||
[source,sh] | ||||||
---- | ||||||
./mill init --base-module MyModule | ||||||
---- | ||||||
.name of generated nested test module (defaults to `test`) | ||||||
|
||||||
* `--jvm-id` (`-j`): version of xref:fundamentals/configuring-jvm-versions.adoc[custom JVM] to configure in `--base-module` | ||||||
[source,sh] | ||||||
---- | ||||||
./mill init --base-module MyModule --jvm-id 17 | ||||||
---- | ||||||
|
||||||
* `--test-module` (`-t`): name of generated nested test module (defaults to `test`) | ||||||
[source,sh] | ||||||
---- | ||||||
./mill init --test-module test | ||||||
---- | ||||||
.name of generated companion object defining constants for dependencies | ||||||
|
||||||
* `--deps-object` (`-d`): name of generated companion object defining dependency constants | ||||||
[source,sh] | ||||||
---- | ||||||
./mill init --deps-object Deps | ||||||
---- | ||||||
.capture properties defined in `pom.xml` for publishing | ||||||
|
||||||
* `--merge` (`-m`): merge build files generated for a multi-module build | ||||||
[source,sh] | ||||||
---- | ||||||
./mill init --publish-properties | ||||||
./mill init --merge | ||||||
---- | ||||||
.merge build files generated for a multi-module build | ||||||
|
||||||
* `--publish-properties` (`-p`): capture properties defined in `pom.xml` for publishing | ||||||
[source,sh] | ||||||
---- | ||||||
./mill init --merge | ||||||
./mill init --publish-properties | ||||||
---- | ||||||
|
||||||
.use cache for Maven repository system | ||||||
* `--cache-repository`: use cache for Maven repository system | ||||||
[source,sh] | ||||||
---- | ||||||
./mill init --cache-repository | ||||||
---- | ||||||
.process Maven plugin executions and configurations | ||||||
|
||||||
* `--process-plugins`: process Maven plugin executions and configurations | ||||||
[source,sh] | ||||||
---- | ||||||
./mill init --process-plugins | ||||||
---- | ||||||
|
||||||
TIP: You can run `mill init` multiple times. It is recommended to run it first without any options. | ||||||
|
||||||
=== Verified projects | ||||||
|
||||||
The conversion has been tested with the following projects: | ||||||
|
@@ -115,7 +127,7 @@ The conversion does not support | |||||
|
||||||
* build extensions | ||||||
* build profiles | ||||||
* non-Java (native) sources | ||||||
* non-Java sources | ||||||
|
||||||
Maven plugin support is limited to | ||||||
|
||||||
|
@@ -134,22 +146,18 @@ These limitations can be overcome by: | |||||
|
||||||
== FAQ | ||||||
|
||||||
.How to fix compilation errors in generated build files? | ||||||
How to fix compilation errors in generated build files? | ||||||
|
||||||
This could happen if a module and task name collision occurs. Either rename the module or enclose the name in backticks. | ||||||
|
||||||
How to fix JPMS `module not found` compilation errors? | ||||||
|
||||||
.How to fix JPMS `module not found` compilation errors? | ||||||
|
||||||
Set https://github.com/tfesenko/Java-Modules-JPMS-CheatSheet#how-to-export-or-open-a-package[additional command line options] | ||||||
for dependencies. | ||||||
|
||||||
Add https://github.com/tfesenko/Java-Modules-JPMS-CheatSheet#how-to-export-or-open-a-package[options] | ||||||
for Java modules to `javacOptions`. | ||||||
|
||||||
.How to fix test compilation errors? | ||||||
How to fix test compilation errors? | ||||||
|
||||||
* The test framework configured may be for an unsupported version; try upgrading the | ||||||
corresponding dependencies. | ||||||
* Mill does not add `provided` dependencies to the transitive dependencies of the nested | ||||||
test module; specify the dependencies again, in one of `ivyDeps`, `compileIvyDeps`, `runIvyDeps`, in the test module. | ||||||
|
||||||
|
||||||
* Mill does not add `compileIvyDeps` dependencies to the transitive dependencies of the nested | ||||||
test module; specify the dependencies again, in `ivyDeps` or `runIvyDeps`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** Usage | ||
|
||
> rm build.mill # remove any existing build file | ||
|
||
> git init . | ||
> git remote add -f origin https://github.com/komamitsu/fluency.git | ||
> git checkout 2.7.3 # multi-module Java project that requires Java 16+ | ||
|
||
> ./mill init --base-module FluencyModule --jvm-id 16 | ||
converting Gradle build | ||
writing Mill build file to fluency-aws-s3/package.mill | ||
writing Mill build file to fluency-core/package.mill | ||
writing Mill build file to fluency-fluentd-ext/package.mill | ||
writing Mill build file to fluency-fluentd/package.mill | ||
writing Mill build file to fluency-treasuredata/package.mill | ||
writing Mill build file to build.mill | ||
init completed, run "mill resolve _" to list available tasks | ||
|
||
> ./mill __.compile | ||
compiling 9 Java sources to ...out/fluency-aws-s3/compile.dest/classes ... | ||
compiling 6 Java sources to ...out/fluency-aws-s3/test/compile.dest/classes ... | ||
compiling 27 Java sources to ...out/fluency-core/compile.dest/classes ... | ||
compiling 8 Java sources to ...out/fluency-core/test/compile.dest/classes ... | ||
|
||
> ./mill fluency-core.test # running all tests takes too long | ||
Test org.komamitsu.fluency.FluencyTest finished, ... | ||
Test org.komamitsu.fluency.validation.ValidatableTest finished, ... | ||
Test org.komamitsu.fluency.buffer.BufferTest finished, ... | ||
Test org.komamitsu.fluency.buffer.BufferPoolTest finished, ... | ||
Test org.komamitsu.fluency.flusher.FlusherTest finished, ... | ||
Test org.komamitsu.fluency.recordformat.MessagePackRecordFormatterTest finished, ... | ||
*/ | ||
Comment on lines
+1
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these files be converted into READMEs since they are just commands and results in comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These commands are automatically used as integration tests and the (expected) output will be asserted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thanks for pointing out. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** Usage | ||
|
||
> rm build.mill # remove any existing build file | ||
|
||
> git init . | ||
> git remote add -f origin https://github.com/mockito/mockito.git | ||
> git checkout v5.15.2 # multi-module Java project that requires Java 17+ | ||
|
||
> ./mill init --base-module MockitoModule --jvm-id 17 # init ignores custom dependency configurations | ||
converting Gradle build | ||
ignoring errorprone dependency (com.google.errorprone,error_prone_core,2.23.0) | ||
init completed, run "mill resolve _" to list available tasks | ||
|
||
> ./mill __.compile # compilation error can be by fixed by using the Mill plugin for ErrorProne | ||
error: ...Unexpected javac output: error: plug-in not found: ErrorProne | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package mill.integration | ||
|
||
import mill.testkit.{IntegrationTester, UtestIntegrationTestSuite} | ||
|
||
abstract class BuildGenTestSuite extends UtestIntegrationTestSuite { | ||
|
||
def initMessage(buildFileCount: Int): String = | ||
s"generated $buildFileCount Mill build file(s)" | ||
|
||
def integrationTest[T](githubSrcZipUrl: String)(f: IntegrationTester => T): T = | ||
super.integrationTest { tester => | ||
println(s"downloading $githubSrcZipUrl") | ||
val zipFile = os.temp(requests.get(githubSrcZipUrl)) | ||
val unzipDir = os.unzip(zipFile, os.temp.dir()) | ||
val sourceDir = os.list(unzipDir).head | ||
// move fails on Windows, so copy | ||
for (p <- os.list(sourceDir)) { | ||
os.copy.into(p, tester.workspacePath, replaceExisting = true, createFolders = true) | ||
} | ||
f(tester) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest is 8.12 but this is not important anyway.I get it now that you are using "dev.gradleplugins:gradle-api" whose latest is 8.11.1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, the version is conventionally extracted into a constant:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks premature to me.