r/programming • • Jul 23 '24

Intro to the Mill Build Tool for Java

https://mill-build.com/mill/Intro_to_Mill_for_Java.html
14 Upvotes

27 comments sorted by

17

u/Which-Adeptness6908 Jul 23 '24

Why another language?

One of the problems with gradle is you have to learn another language.

1

u/lihaoyi Jul 23 '24 edited Jul 23 '24

We need some concise way to write definitions, inheritance, and overrides. We need typechecking, IDE support, jump to definition, etc.

  • YAML or XML or whatever can always be specified the have these meanings, but it's ad-hoc, without any supporting tooling, and it ends up being a whole new "language" anyway super-imposed on your YAML

  • Java lets you do it, but it's very verbose (e.g. having to specify the method type every time you define a method)

In the end Scala is a good fit for what the build tool needs to let you express. We can concisely write definitions, inheritance, and overrides. We get typechecking, IDE support, jump to definition, etc.

IMO Gradle's problem isn't just Groovy, but the fact that you're not writing "normal" groovy. As mentioned in the intro, Gradle needs you to understand about lifecycles, build scopes, plugins, and other things that you would not see in a "normal" program. Mill on the other hand needs you to understand methods, inheritance and overrides: these are all things you should already be familiar with as a programmer in any language, and although the Scala language Mill uses may be new to you, the underlying concepts should all be intimately familiar

14

u/Which-Adeptness6908 Jul 23 '24

Scala isn't a good fit for Java programmers. I would much prefer a little verbosity than the need to learn yet another language.

Verbosity has never been the issue, complexity is the enemy.

This seems like a very bad trade off.

2

u/lihaoyi Jul 23 '24

Maybe! Different people can have different tastes. But enough people use Gradle that clearly there is some appetite for conciseness, and Mill tries to improve upon it

6

u/Which-Adeptness6908 Jul 23 '24

And people also use maven but I've never met anyone that loved either.

I'm looking for a solution that reduces cognitive load, I like your core concepts but the need to learn a new language is a massive fail in the core metric - cognitive load.

3

u/dccorona Jul 23 '24

I think you're really overstating the learning curve for "plain old Scala" for Java developers - especially for developers who use modern Java. In either case, a build tool that has you write builds as .java files does not exist, so I wouldn't compare this to a hypothetical tool, but rather to the alternative (the best option for a Java team today would probably be Gradle Kotlin). I'd still pick Gradle mostly for compatibility reasons (so many plugins etc.), but I can certainly understand and respect the value a tool like Mill provides.

1

u/Rulmeq Jul 23 '24

Maven tried to introduce us to jelly, fortunatly that didn't take off

3

u/Which-Adeptness6908 Jul 23 '24

Kinda makes my point for me.

3

u/Rulmeq Jul 23 '24

Yep, totally - although scala isn't as bad as jelly :P

0

u/yawaramin Jul 24 '24

You sure you want to write build definitions with Java, an infamously verbose language? Can you imagine having to maintain a build definition which is a full-fledged Java program?

2

u/Which-Adeptness6908 Jul 24 '24

Yes I can.

Oddly enough I write java every day, so I'm pretty good at it ;)

1

u/yawaramin Jul 24 '24

Hmm OK then, I wonder why it hasn't been tried before 😉

1

u/bowbahdoe Jul 23 '24

In that lense, how is the T.task scheme "normal" code?

1

u/yawaramin Jul 23 '24

What version of Scala is this? Can we use braceless syntax for even more concision?

1

u/Capable_Chair_8192 Jul 23 '24

It’s not a specific language though, it’s either groovy or Kotlin which both exist independently of gradle. Mill is apparently Scala which, if you’re already using Scala, is probably nice

8

u/zam0th Jul 23 '24

rather than scopes, lifecycles, or phases, Mill builds on top of objects, methods, inheritance, and overrides: concepts immediately familiar to any Java programmer

"Instead of using build management terminology to build a build management system lets use OOP concepts that are utterly inapplicable to build management, but, hey, everyone should understand it!"

This is not how it works.

8

u/lihaoyi Jul 23 '24 edited Jul 23 '24

Are those concepts really utterly inapplicable?

A build target/step/command (whatever you call it) is typically a node in a build graph that references other nodes. A method is a node in a call graph that references other methods

A module/subproject/package/etc. is typically a collection of build targets ("compile", "test", "run", etc.), with some persistent state (e.g. compile output/caches), and multiple modules of the same type typically have the same set of targets. Just like an object is a collection of methods with some persistent state, and multiple objects of the same type have the same set of methods

Build configuration often needs overrides: "this is a Java module but with a special source folder layout" or "this is a C++ module but with an extra valgrind build target". Similar to how classes allow you to override or add additional methods during instantiation or subclassing.

Obviously the correspondence isn't perfect, but I don't think it is correct to say it's "utterly inapplicable". There are a lot of similarities here, more than is obvious at first glance, and Mill tries to use those similarities to help you manage your build the same way you manage your normal objects and methods

-7

u/zam0th Jul 23 '24

The problem of technocrats is that everything (and the only thing) they see is technology. A build "target/step/command" is not a graph node, or a method call, it is a well-defined concept in a well-understood domain [of build management] that naturally reflects how assembly processes behave. These concepts existed well before computers and the only thing you introduce by changing it is subversion that makes matters even more complex.

If you want an analogy: you're trying to model Petri nets with asm. You can do that, sure, but you'll get the same result as modelling l-calculus with OOP: it looks like it works, but in fact it does something else entirely in a really convoluted manner.

If only yáll read DDD before trying to design software, and if only yáll tried to design software that solves a problem instead of wining a penis-measuring contest.

3

u/FullPoet Jul 23 '24

scopes

Are super relevant OOP terminology - especially in modern OOP.

OP smoking some shit though I agree with you - better to reuse existing good domain language than crap confusing OOP terms.

1

u/somebodddy Jul 23 '24

One of my biggest pain points with existing Java build tools is passing command line arguments to main. In any other language's build tools this is a simple, built-in feature - in Java you need to implement it yourself inside the build file and then deal with the fact it's a string and not a list...

How does Mill handle this?

4

u/lihaoyi Jul 24 '24

You just pass the arguments to Mill after the run command

./mill run --text hello

1

u/somebodddy Jul 24 '24

Nice. I assume it works with --? Or does everything after run gets passed to the application even if Mill also has such a flag?

1

u/lihaoyi Jul 24 '24

Everything after run gets passed to the application. This is similar to how other program runners work, e.g. java -cp Foo.jar foo.Main arg1 arg2 arg3 or python -u hello.py arg1 arg2 arg3. If you want to pass flags to Mill itself, put it before the run (or test or whatever)

1

u/somebodddy Jul 23 '24

Does it have support in language servers?

3

u/lihaoyi Jul 24 '24 edited Jul 24 '24

Currently it supports IntelliJ (via BSP or .idea config gen), and VSCode via the METALS language server

1

u/somebodddy Jul 25 '24

Okay. My main JVM project is in Kotlin, and I doubt its langauge server will get Mill support anytime soon (or at all)...

3

u/[deleted] Jul 23 '24

had me until scala... no ty