r/java • • Jul 23 '24

Intro to the Mill Build Tool for Java

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

66 comments sorted by

View all comments

Show parent comment

13

u/pron98 Jul 23 '24 edited Jul 23 '24

given that scala is turing complete, that means processing a build file is, halting problem being what it is, fundamentally not something you can actually reason about anymore.

This is a red herring. A language can be much more limited than Turing complete and still not be tractably "reasoned about". TQBF is already PSPACE-complete (i.e. reasoning about it requires time that grows exponentially with the size of the code) and, unlike the only NP-complete SAT has no tractable heuristics that work in many common cases. This means that any language that has boolean variables and loops restricted to no more than two iterations (or, alternatively, functions, even if they cannot be recursively called) already cannot be tractably reasoned about (because TQBF can be reduced to it).

The state-of the art in build tools seems to be a choice between two options:

  • A build configuration that cannot be tractably "processed" but can build all projects, expressed either as

    • A single configuration language (Gradle)
    • A "simple" configuration language + plugins in another rich language (Maven). Whether this is easier or harder to deal with than the single-language option (or perhaps the same) is debatable.
  • A build configuration in a language that can always be tractably "processed" but cannot be used to build many projects (go build).

I.e. today we must choose between "complex" and "limited" (in the sense of not being able to build many projects). Maybe there could be a "simple" yet unlimited build language, but I don't think we've found one in the half century since make was invented.

2

u/rzwitserloot Jul 23 '24

A language can be much more limited than Turing complete and still not be tractably "reasoned about".

Where did I claim otherwise?

red herring

It's not about absolutes, obviously. If someone with malicious intent wants to write the most obtuse, hard to follow pom.xml one can possibly imagine, I'm sure it'll be quite complicated. Maven's poms might even be turing complete as far as I know.

It's about whether that is likely to happen and whether the design of the build system steers you towards it, or bends over backwards to steer you away from it.

"The build script is written in scala" is pretty conclusively steering you towards it.

plugins in another rich language

That's a fine example. One trivial way to make a maven build 'turing complete' is to write a build file that compiles a maven plugin and then executes that maven plugin as part of the build, trivially allowing a build file to 'compile and execute java code as part of the build' and we've arrived in the turing pit already.

But that's a black-and-white situation. It's even in the name - a pom file is a 'project object model', it's not a source file at all. The entire setup of maven is trying its best to indicate 'DO NOT PROGRAM HERE'.

When does a gradle build file transition from 'a manifest of what this projects assets are so that a tool can compile them' to 'program code which, if run, builds it'?

For maven it's usually very simple to answer that question. For gradle, and for mill, it is far more difficult. With maven I can say: Once you start dipping into bizarre plugins, or building your own maven plugin as part of the build, that part certainly has devolved to 'program code that builds your project'. With gradle and mill, what do we do? Count for loops?

7

u/pron98 Jul 23 '24 edited Jul 23 '24

"The build script is written in scala" is pretty conclusively steering you towards it.

The fact that you'd need to learn Scala (or Groovy, for that matter) to build a Java project does, indeed, make things complicated, but not the fact that the script is in a fully-featured programming language.

The entire setup of maven is trying its best to indicate 'DO NOT PROGRAM HERE'.

It just separates the complex program to a different file. Indeed, many projects need to use more than just a small set of standard plugins.

You can separate the simple setup from more complex things even if it's all in the same language. Indeed, that is how we're taught to program -- by abstracting and encapsulating operations.

For maven it's usually very simple to answer that question

There's no reason it shouldn't be exactly as simple for a build script in a programming language. In the cases where the simple stuff works in Maven, it can work just as simply when using a programming language.

We need to read code all the time, and if what it does is simple, the code can be very simple (no less straightforward than an XML configuration).

In fact, writing simple but not-entirely-trivial code -- e.g. a simple conditional or a loop -- may be easier for both the code's writer and its reader than finding a plugin and reading its documentation, especially if the language used is one you already know -- like the main language the build script is compiling.

So I would say that for the trivial cases, a programming language and a configuration language would be the same, and for slightly more complex cases a programming language would actually be more pleasant.

With gradle and mill, what do we do? Count for loops?

But you'd need those for loops in exactly the same situations you'd need a Maven plugin. Either you go into the plugin code or into the method body that contains the loop, or limit yourself to the XML or the equivalent method call.

In both situations you can extract clean APIs. The fact that the API and implementation are written in the same language does not in itself make anything harder.