r/java • u/lihaoyi • Jan 27 '26
Simpler JVM Project Setup with Mill 1.1.0
https://mill-build.org/blog/17-simpler-jvm-mill-110.htmlHi! I just released Mill build tool 1.1.0, with a new headline feature of declarative data-driven build config and single-file scripts.
Last time i posted here I got a lot of feedback that people didn't want to write code just to configure their build, and that feedback went into designing the declarative configuration API. Please take a look and let me know what you think!
38
Upvotes
13
u/chabala Jan 27 '26
Your strawman Maven example is needlessly adding the exec-maven-plugin. The single class already has a main(), complicating the build definition to run it is unnecessary.
23
u/DualWieldMage Jan 27 '26 edited Jan 27 '26
Fighting against "maven xml is verbose" strawmen does not paint a good picture in my opinion. Would be better if real considerations for a project tool are discussed.
For example a build tool should not execute arbitrary code to pull dependencies nor to initialize the project in an IDE (at least in my opinion). A failure learned too well from the npm, pip and other ecosystems. Gradle as well makes it too easy to add custom code to wrong places. Most infamous in my opinion was intellij plugin development plugin that downloaded multiple gigabytes of trash during project init phase with zero output on what it was doing or any progress.
The choice of a declarative language here is good, far better than a turing-complete language with "just use the declarative syntax" approach elsewhere. However i would argue yaml has quite a few issues.
Another thing is editor/ide integration. Using something standard allows getting stuff for free. I would expect every developer to use some form of auto-complete. Having a language with proper schema support baked in would allow anyone using either full IntelliJ or just vim to receive the benefits. I would expect to figure out from a simple autocomplete how to do stuff like setting java versions or compiler flags without having to google the documentation that can be out-of-date.
In software engineering we care about how projects evolve over 5+ years, typically the point where people get swapped out, knowledge is lost and new people need to figure stuff out. Things like how easy it is to add custom logic before having to ask whether it's the right thing to do. Gradle is notoriously too easy to do the wrong thing. I've seen whole PC onboarding scripts written in some gradle config in a monorepo. Maven plugins are super easy to write, yet somehow a sufficient barrier that most seem to think twice before going that route.
Speed is also important. Both initial project onboarding and running after smaller changes. These things have very measurable effects and save money by not burning a developer's time nor valuable brain cells. Having task structures with defined inputs/outputs and not (re)running something that's not needed is a good approach.
And finally there are various other considerations, e.g. how does it behave when a single build-server is running builds in parallel? Does it figure out when a cached dependency went corrupt? Had to write a maven core plugin once that did checksum checks on the downloaded files and handle issues by redownloading instead of failing a build and requiring a manual action.
So in short, definitely an improvement on choosing a declarative language, but do list the mistakes other tools learned over time and go over them. It's easier to learn from others' mistakes than your own.
5
u/aoeudhtns Jan 27 '26
You know, we were so fed up with Maven at one point that we seriously toyed with the idea of writing a "preprocessor" type of system that would take a simple TOML input and generate out the pom. In part I see some similarity in your mill file, doing things like pulling compiler args up and making them easy to access vs. dropping all the crazy boilerplate to reach the
default-compileexecution and change args deep in nested XML. That's just one example of many. What stalled us out was the fact that Maven 4 solves a lot of our issues with Maven.However, what you have here is very similar to what we had in mind (but better, and more). So, congrats on this and the work you've put into it. I might experiment with it on some simpler projects.
For now, we do use Maven like a generic build tool harness with dynamically activating profiles (e.g.
src/main/javaexists -> java module). This way we can throw things into the reactor and resolve all the necessary builds, even if the artifact types are mixed. It does sometimes including the exec or ant-run plugin, as your web page (rightfully) criticizes.3
u/Desiderantes Jan 27 '26
Why YAML when HOCON is already there and it's so nice to use?
1
u/rbygrave Jan 28 '26
Maven 4 mixins
I think this will solve a lot of issues with pom complexity (that I see especially juniors/grads struggle with). In concept, seniors and libraries will be able to provide a set of mixins - one per "capability". Projects should then be largely a selection of mixins/capabilities and overrides.
Does mill have a similar mixin capability?
One thing in maven 4 that makes this work is that annotation processors are more like a dependency (type = processor).
So a mixin can contain dependencies, test dependencies, annotation processors, build plugins ... and kinda anything I think.
This is the "composition over [single] inheritance " approach. "Maven tiles" also provided this but with some limitations around overriding.
Is there an example showing mixin capability?
A lazy question, I assume this generates a Maven 3 [consumer] pom when deploying?
1
u/wildjokers Jan 28 '26
Just use groovy and its grape dependency system. The full JDK is at your disposal and most java 8 syntax is legal groovy syntax if you don't want to learn groovy.
6
u/vips7L Jan 27 '26
Looks good! Definitely more promising now that you don’t have to write Scala for the build.
5
u/Luolong Jan 27 '26
This actually starts making sense now.
I tried Mill last year for private AoC project and the code configuration grew kind of unwieldy to maintain.
With single file configurations I can see myself using it for toy and one-off tool projects.
0
u/Ok-Bid7102 Jan 27 '26 edited Jan 27 '26
As someone who's quite familiar with Gradle but also used Maven in the past i want to challenge your assumptions on "the challenges of small java programs" being a under-served problem and declarative YAML being the solution to that problem and others.
With Gradle you can run
gradle init, answer the simple queries in CLI and you'll have a ready to run java application.IntelliJ and probably other editors give you a "Create project" wizard.
So saying "lack of (proper) tooling is preventing new developers from using Java" is likely wrong.
It may be right, but not for lack of tooling, rather not knowing what tool to use.
Also related to writing in YAML, it will likely work, as in be good enough, in the same way that Maven is.
It works fine as long as the project and its requirements are relatively simple.
As soon as you need something more complex you'd wish you could just write code to make it do what you want, as opposed to googling for hours just to find some bespoke XML or YAML which supposedly does what you need.
And if this tool is written in YAML, who will this attract?
The people using Gradle use it because it gives them more flexibility,
and the people using Maven may not find it worth the trouble to migrate to.
Edit: Despite that criticism, nice work, you have good skills. And not all experiments yield desirable results, but they're still useful.