Skip to content
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

Extended mill init to support an existing Maven project #3756

Merged
merged 71 commits into from
Nov 14, 2024

Conversation

ajaychandran
Copy link
Contributor

@ajaychandran ajaychandran commented Oct 16, 2024

This PR adds support to convert a Maven build to Mill by generating Mill build file(s) from POM file(s).
The generator output should be considered scaffolding and will likely require edits to complete conversion.

Capabilities

The conversion

  • handles deeply nested modules
  • captures project metadata
  • configures dependencies for scopes:
    • compile
    • provided
    • runtime
    • test
  • configures testing frameworks:
    • JUnit 4
    • JUnit 5
    • TestNG
  • configures multiple, compile and test, resource directories

Limitations

The conversion does not support:

  • build extensions
  • build profiles
  • plugins, other than maven-compiler-plugin

Future work

Add support for:

Resolves #3449.

@lihaoyi
Copy link
Member

lihaoyi commented Oct 17, 2024

For a multi-module project the package.mill files are generated for sub-modules but they are not recognized by Mill. See integration test MillInitMavenTests for details.

@ajaychandran for package.mill files to be recognized, you need the magic import import $packages._ in the top-level `build.mill

Should a new task be defined for provided dependencies? JavaModule.providedIvyDeps?

IIRC provided dependencies correspond to Mill's compileIvyDeps

@ajaychandran
Copy link
Contributor Author

ajaychandran commented Oct 17, 2024

@lihaoyi Thanks for the tips.

Now, the conversion fails with

super-csv/package.mill:7:71: type BaseMavenModule is not a member of object build_.package_

I am not sure why this is happening. Could it be because build.mill has a package RootModule (for publishing the Maven parent module)?

Below is the output of generatedScriptSources.
build.mill

package build_
import _root_.{build_ => $file}
import build_.{package_ => build}
import _root_.mill.runner.MillBuildRootModule
@_root_.scala.annotation.nowarn
object MillMiscInfo extends mill.main.RootModule.Info(
  Vector("/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.14/scala-library-2.13.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/mill-moduledefs_2.13/0.11.1/mill-moduledefs_2.13-0.11.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/scalafmt-dynamic_2.13/3.8.3/scalafmt-dynamic_2.13-3.8.3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_2.13/2.3.0/scala-xml_2.13-2.3.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/alexarchambault/windows-ansi/windows-ansi/0.0.5/windows-ansi-0.0.5.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/get-coursier/interface/1.0.19/interface-1.0.19.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/mainargs_2.13/0.7.6/mainargs_2.13-0.7.6.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/requests_2.13/0.9.0/requests_2.13-0.9.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.5.7/logback-classic-1.5.7.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jgrapht/jgrapht-core/1.4.0/jgrapht-core-1.4.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/guru/nidi/graphviz-java-min-deps/0.18.1/graphviz-java-min-deps-0.18.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.13/0.4.0/sourcecode_2.13-0.4.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.14.0/jna-5.14.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna-platform/5.14.0/jna-platform-5.14.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/eed3si9n/jarjarabrams/jarjar-abrams-core_2.13/1.14.0/jarjar-abrams-core_2.13-1.14.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/scalaparse_2.13/3.1.1/scalaparse_2.13-3.1.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/os-lib_2.13/0.11.1/os-lib_2.13-0.11.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/upickle_2.13/3.3.1/upickle_2.13-3.3.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/pprint_2.13/0.9.0/pprint_2.13-0.9.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/fansi_2.13/0.5.0/fansi_2.13-0.5.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline/3.26.3/jline-3.26.3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/get-coursier/coursier_2.13/2.1.14/coursier_2.13-2.1.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.14/scala-compiler-2.13.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/ow2/asm/asm-tree/9.7/asm-tree-9.7.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-embedder/3.9.9/maven-embedder-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-connector-basic/1.9.22/maven-resolver-connector-basic-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-supplier/1.9.22/maven-resolver-supplier-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-transport-file/1.9.22/maven-resolver-transport-file-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-transport-http/1.9.22/maven-resolver-transport-http-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-transport-wagon/1.9.22/maven-resolver-transport-wagon-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/scalafmt-interfaces/3.8.3/scalafmt-interfaces-3.8.3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/scalafmt-sysops_2.13/3.8.3/scalafmt-sysops_2.13-3.8.3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/typesafe/config/1.4.3/config-1.4.3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.18/jansi-1.18.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/slf4j/slf4j-api/2.0.15/slf4j-api-2.0.15.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_2.13/2.12.0/scala-collection-compat_2.13-2.12.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/geny_2.13/1.1.1/geny_2.13-1.1.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/ch/qos/logback/logback-core/1.5.7/logback-core-1.5.7.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jheaps/jheaps/0.11/jheaps-0.11.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/guru/nidi/graphviz-java/0.18.1/graphviz-java-0.18.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/eed3si9n/jarjar/jarjar/1.14.0/jarjar-1.14.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.14/scala-reflect-2.13.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/fastparse_2.13/3.1.1/fastparse_2.13-3.1.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/ujson_2.13/3.3.1/ujson_2.13-3.3.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/upack_2.13/3.3.1/upack_2.13-3.3.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/upickle-implicits_2.13/3.3.1/upickle-implicits_2.13-3.3.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/kohlschutter/junixsocket/junixsocket-native-common/2.10.0/junixsocket-native-common-2.10.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/kohlschutter/junixsocket/junixsocket-common/2.10.0/junixsocket-common-2.10.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-core_2.13/2.13.5.2/jsoniter-scala-core_2.13-2.13.5.2.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/get-coursier/coursier-core_2.13/2.1.14/coursier-core_2.13-2.1.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/get-coursier/coursier-cache_2.13/2.1.14/coursier-cache_2.13-2.1.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/get-coursier/coursier-proxy-setup/2.1.14/coursier-proxy-setup-2.1.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/java-diff-utils/java-diff-utils/4.12/java-diff-utils-4.12.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/ow2/asm/asm/9.7/asm-9.7.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-settings/3.9.9/maven-settings-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-settings-builder/3.9.9/maven-settings-builder-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-core/3.9.9/maven-core-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-plugin-api/3.9.9/maven-plugin-api-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-model/3.9.9/maven-model-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-model-builder/3.9.9/maven-model-builder-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-builder-support/3.9.9/maven-builder-support-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-api/1.9.22/maven-resolver-api-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-util/1.9.22/maven-resolver-util-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/shared/maven-shared-utils/3.4.2/maven-shared-utils-3.4.2.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/google/inject/guice/5.1.0/guice-5.1.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/google/guava/guava/33.3.0-jre/guava-33.3.0-jre.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.2/failureaccess-1.0.2.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/4.0.0/plexus-utils-4.0.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-classworlds/2.8.0/plexus-classworlds-2.8.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/eclipse/sisu/org.eclipse.sisu.plexus/0.9.0.M3/org.eclipse.sisu.plexus-0.9.0.M3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-sec-dispatcher/2.0/plexus-sec-dispatcher-2.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-cipher/2.0/plexus-cipher-2.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-interpolation/1.27/plexus-interpolation-1.27.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/commons-cli/commons-cli/1.8.0/commons-cli-1.8.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-spi/1.9.22/maven-resolver-spi-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-named-locks/1.9.22/maven-resolver-named-locks-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-impl/1.9.22/maven-resolver-impl-1.9.22.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-resolver-provider/3.9.9/maven-resolver-provider-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.5.14/httpclient-4.5.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.4.16/httpcore-4.4.16.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/commons-codec/commons-codec/1.17.1/commons-codec-1.17.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/slf4j/jcl-over-slf4j/1.7.36/jcl-over-slf4j-1.7.36.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/wagon/wagon-provider-api/3.5.3/wagon-provider-api-3.5.3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-parallel-collections_2.13/1.0.4/scala-parallel-collections_2.13-1.0.4.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/guru/nidi/com/eclipsesource/j2v8/j2v8_linux_x86_64/4.6.0/j2v8_linux_x86_64-4.6.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/ow2/asm/asm-commons/9.6/asm-commons-9.6.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.14.0/commons-lang3-3.14.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/upickle-core_2.13/3.3.1/upickle-core_2.13-3.3.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/alexarchambault/concurrent-reference-hash-map/1.1.0/concurrent-reference-hash-map-1.1.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/get-coursier/coursier-util_2.13/2.1.14/coursier-util_2.13-2.1.14.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/io/get-coursier/jniutils/windows-jni-utils/0.3.3/windows-jni-utils-0.3.3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-archiver/4.9.0/plexus-archiver-4.9.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-container-default/2.1.1/plexus-container-default-2.1.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/virtuslab/scala-cli/config_2.13/0.2.1/config_2.13-0.2.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-repository-metadata/3.9.9/maven-repository-metadata-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/maven/maven-artifact/3.9.9/maven-artifact-3.9.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/eclipse/sisu/org.eclipse.sisu.inject/0.9.0.M3/org.eclipse.sisu.inject-0.9.0.M3.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-component-annotations/2.1.0/plexus-component-annotations-2.1.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/aopalliance/aopalliance/1.0/aopalliance-1.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-xml/3.0.0/plexus-xml-3.0.0.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-io/3.4.1/plexus-io-3.4.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/commons-io/commons-io/2.16.1/commons-io-2.16.1.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/commons/commons-compress/1.26.2/commons-compress-1.26.2.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/iq80/snappy/snappy/0.4/snappy-0.4.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/tukaani/xz/1.9/xz-1.9.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/com/github/luben/zstd-jni/1.5.5-10/zstd-jni-1.5.5-10.jar", "/home/aj/.cache/coursier/v1/https/repo1.maven.org/maven2/org/apache/xbean/xbean-reflect/3.7/xbean-reflect-3.7.jar", "/home/aj/github/ajaychandran/mill/out/runner/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/runner/client/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/server/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/codesig/compile.dest/classes", "/home/aj/github/ajaychandran/mill/runner/linenumbers/resources", "/home/aj/github/ajaychandran/mill/out/runner/linenumbers/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/bsp/buildInfoResources.dest", "/home/aj/github/ajaychandran/mill/out/bsp/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/scalanativelib/worker-api/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/scalanativelib/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/scalajslib/worker-api/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/scalajslib/buildInfoResources.dest", "/home/aj/github/ajaychandran/mill/out/scalajslib/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/kotlinlib/worker/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/kotlinlib/buildInfoResources.dest", "/home/aj/github/ajaychandran/mill/out/kotlinlib/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/testrunner/entrypoint/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/testrunner/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/scalalib/api/buildInfoResources.dest", "/home/aj/github/ajaychandran/mill/out/scalalib/api/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/resolve/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/util/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/client/buildInfoResources.dest", "/home/aj/github/ajaychandran/mill/out/main/client/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/api/buildInfoResources.dest", "/home/aj/github/ajaychandran/mill/out/main/api/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/define/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/eval/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/buildInfoResources.dest", "/home/aj/github/ajaychandran/mill/out/main/compile.dest/classes", "/home/aj/github/ajaychandran/mill/scalalib/resources", "/home/aj/github/ajaychandran/mill/out/scalalib/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/idea/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/main/init/exampleList.dest", "/home/aj/github/ajaychandran/mill/out/main/init/compile.dest/classes", "/home/aj/github/ajaychandran/mill/out/dist/runClasspath.dest"),
  "/home/aj/github/ajaychandran/mill/out/integration/feature/init/local/testOnly.dest/sandbox/run-2",
  "/home/aj/github/ajaychandran/mill/out/integration/feature/init/local/testOnly.dest/sandbox/run-2/out",
  "/home/aj/github/ajaychandran/mill/out/integration/feature/init/local/testOnly.dest/sandbox/run-2"
)
import MillMiscInfo._

//MILL_ORIGINAL_FILE_PATH=/home/aj/github/ajaychandran/mill/out/integration/feature/init/local/testOnly.dest/sandbox/run-2/build.mill
//MILL_USER_CODE_START_MARKER


import mill._
import mill.javalib._
import mill.javalib.publish._
import _root_._

trait BaseMavenModule extends MavenModule with PublishModule {

  override def pomSettings = PomSettings(
    s"""Super CSV parent project""".stripMargin,
    "Super CSV",
    "https://github.com/super-csv/super-csv",
    Seq(
      License("Apache License, Version 2.0", "Apache License, Version 2.0", "http://www.apache.org/licenses/LICENSE-2.0.html", false, false, "repo")
    ),
    VersionControl(
      Option("https://github.com/super-csv/super-csv"),
      Option("scm:git:git@github.com:super-csv/super-csv.git"),
      Option("scm:git:git@github.com:super-csv/super-csv.git"),
      Option("v2.4.0")
    ),
    Seq(
      Developer("kbg", "Kasper Graversen", "", Option(null), Option(null)),
      Developer("jamesbassett", "James Bassett", "", Option(null), Option(null)),
      Developer("ddv36a78", "Dominique De Vito", "", Option(null), Option(null))
    )
  )

  override def publishVersion = "2.4.0"

  trait Tests extends TestModule.Junit4 with MavenTests {

    override def defaultCommandName() = "test"

    override def ivyDeps = super.ivyDeps() ++ Agg(
      ivy"com.novocode:junit-interface:0.11"
    )
  }
}

abstract class package_  extends RootModule with BaseMavenModule {

  override def artifactName = "super-csv-parent"

  override def pomPackagingType = PackagingType.Pom
}

object package_ extends package_ {
  final lazy val `super-csv-distribution`: _root_.build_.`super-csv-distribution`.package_.type = _root_.build_.`super-csv-distribution`.package_ // subfolder module reference
final lazy val `super-csv-dozer`: _root_.build_.`super-csv-dozer`.package_.type = _root_.build_.`super-csv-dozer`.package_ // subfolder module reference
final lazy val `super-csv-joda`: _root_.build_.`super-csv-joda`.package_.type = _root_.build_.`super-csv-joda`.package_ // subfolder module reference
final lazy val `super-csv`: _root_.build_.`super-csv`.package_.type = _root_.build_.`super-csv`.package_ // subfolder module reference
final lazy val `super-csv-java8`: _root_.build_.`super-csv-java8`.package_.type = _root_.build_.`super-csv-java8`.package_ // subfolder module reference
final lazy val `super-csv-benchmark`: _root_.build_.`super-csv-benchmark`.package_.type = _root_.build_.`super-csv-benchmark`.package_ // subfolder module reference
  override lazy val millDiscover: _root_.mill.define.Discover = _root_.mill.define.Discover[this.type]

}

super-csv/package.mill

package build_.`super-csv`
import _root_.{build_ => $file}
import build_.{package_ => build}
object MillMiscSubFolderInfo
extends mill.main.SubfolderModule.Info(
  os.Path("/home/aj/github/ajaychandran/mill/out/integration/feature/init/local/testOnly.dest/sandbox/run-2/super-csv"),
  _root_.scala.Seq("super-csv")
)
import MillMiscSubFolderInfo._

//MILL_ORIGINAL_FILE_PATH=/home/aj/github/ajaychandran/mill/out/integration/feature/init/local/testOnly.dest/sandbox/run-2/super-csv/package.mill
//MILL_USER_CODE_START_MARKER


import mill._
import mill.javalib._
import mill.javalib.publish._

abstract class package_  extends mill.main.SubfolderModule with build.BaseMavenModule {

  override def artifactName = "super-csv"

  override def javacOptions = Seq(
    "-source",
    "1.5",
    "-target",
    "1.5"
  )


  object test extends Tests {

    override def ivyDeps = super.ivyDeps() ++ Agg(
      ivy"junit:junit:4.12"
    )
  }

}
object package_ extends package_ {
  
  
}

@lihaoyi
Copy link
Member

lihaoyi commented Oct 18, 2024

@ajaychandran looks like the issue is trait BaseMavenModule needs to live within the object package for it to get picked up correctly

@ajaychandran
Copy link
Contributor Author

@lihaoyi This is ready for review.

The issue was resolved by adding the $file import in package.mill files.

One criticism of this solution is that the root task namespace (mill resolve _) gets cluttered with the tasks of the root module. This could be a problem if a "name collision" occurs.
On the upside, this allows running tasks like mill compile (post initialization). IMO this offers a better user experience.

@ajaychandran ajaychandran marked this pull request as ready for review October 18, 2024 06:23
@lihaoyi
Copy link
Member

lihaoyi commented Oct 19, 2024

@ajaychandran did a pass and left some comments. Probably will take a few more passes to get it merged, but looks promising.

Some high-level comments:

  • Please update the PR description with details of what future maintainers or users would want to read.

    • For me, I am most interested in the scope of this feature: it obviously cannot convert every Maven build under the sun with all possible plugins, but it can convert simple maven builds, so where is the line drawn for this particular implementation?
    • There are probably other things that you would expect others sending you a large PR to write in the description
  • Add an integration test that takes the Netty codebase we use in https://github.com/com-lihaoyi/mill/blob/main/example/thirdparty/netty/build.mill, runs your converter, and then runs the subset of the netty module tests that work.

    • Not everything will work - some of the modules require calling make and compiling C code or running an H2Spec or Autobahn server - and that is expected.
    • But we should assert that the modules that are supported do compile, the tests which are supported do pass, and the correct number of test suites are being run (by looking at show __.discoveredTestClasses).
    • We should also have comments enumerating the modules/tests that not pass, and why it is expected they do not pass (e.g. native C dependencies, requiring external servers running, etc.)
  • Let's move all this maven logic and dependencies out of the main classpath into an isolated subprocess or classloader. This will avoid risking artifact collisions in the main classpath

@lihaoyi
Copy link
Member

lihaoyi commented Nov 11, 2024

@ajaychandran for the golden files, we've typically just done .replaceAll("\r\n", "\n") to fix up line endings before comparison. Typically needs to be done on both the expected and actual output, but otherwise works great

@lihaoyi
Copy link
Member

lihaoyi commented Nov 11, 2024

I think this looks good overall. I tried it out on https://github.com/iluwatar/java-design-patterns, and apart from parts of the codebase that needed compiler plugins (e.g. @lombok.extern.slf4j.Slf4j) or maven plugins (e.g. spring-boot-maven-plugin) it seems that it mostly worked and I got most of the codebase compiling and testing. Nice work!

Notably, I needed one upstream patch to avoid class file size limitations to get things compiling:

--- a/main/define/src/mill/define/Discover.scala
+++ b/main/define/src/mill/define/Discover.scala
@@ -147,7 +147,7 @@ object Discover {
         // by wrapping the `overridesRoutes` in a lambda function we kind of work around
         // the problem of generating a *huge* macro method body that finally exceeds the
         // JVM's maximum allowed method size
-        val overridesLambda = q"(() => $overridesRoutes)()"
+        val overridesLambda = q"(new Function0[(Seq[String], Seq[mainargs.MainData[_, _]], Seq[String])]{def apply() = $overridesRoutes})()"
         q"$lhs -> $overridesLambda"
       }

@ajaychandran ajaychandran marked this pull request as draft November 12, 2024 09:44
@ajaychandran
Copy link
Contributor Author

Investigating the CI failure with act.
Changed the PR to Draft.

@lihaoyi lihaoyi marked this pull request as ready for review November 14, 2024 02:18
@lihaoyi lihaoyi merged commit 3b94c5d into com-lihaoyi:main Nov 14, 2024
25 checks passed
@lihaoyi
Copy link
Member

lihaoyi commented Nov 14, 2024

@ajaychandran i ended up disabling the netty tests in windows for now. I'll close out this bounty and the previous one for the OS-Lib instrumentation

@lefou lefou added this to the 0.12.3 milestone Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support mill init from an existing Maven project (1500USD Bounty)
3 participants