Allow running standalone single-file scripts using Mill, Attempt #2 #5826
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Second pass at #5714, a re-run of #5820 which required more baking before merge
Initial pass, this works:
The basic approach is
-f
/--file
to be passed to specify a script file to use rather thanbuild.mill
-f
is passed, use an alternate shortenedMillBuildBootstrap
process that has a single build stage with a hard-codedRootModule
based on the extension of the script:mill.meta.ScriptModule.Java
,.Scala
, or.Kotlin
In the common case where someone wants to just run a script, they can run:
As a shorthand for the full
./mill -f Foo.java run --text hello
. We special-case the first token ending with.java
,.scala
, or.kt
to support this. I expect this would be what people want to do with their scripts the vast majority of the time, so it deserves its own extra-concise syntax even if it has some theoretical overlap with user-defined tasks ending with those namesOther notes:
For single-file projects, we assign them a subfolder in the out folder where all the build takes place e.g.
foo/bar/Baz.kt
gets assignedout/foo/bar/Baz.kt/
as its out folder. Normal tasks and modules won't normally have.
s in their name, so this ensures that the single-file projects won't collide with normal module and task output filesSome of the task outputs from
mill.javalib.publish
have been given short-handsupickle.Reader
s for writing them in the YAML build header. I expect we will need to add more such shorthands in futureStarted with some basic doc sections on the per-language
intro.adoc
andmodule-config.adoc
pages touching on usage of these single-file projects, but I expect we'll need more documentationFor this PR, the single-file projects are entirely standalone and not connected to any enclosing Mill build, but that may be something we can integrate in future to allow single-file projects to define
moduleDeps
on the enclosingbuild.mill
's modulesTested with a example tests