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

Add mill 0.12.8 build support #438

Open
wants to merge 5 commits into
base: 0.23-mill
Choose a base branch
from

Conversation

carlosrogue
Copy link

@carlosrogue carlosrogue commented Feb 16, 2025

Add initial mill build support. Some commands to execute are:

  • mill run to execute the application
  • mill -w compile for incremental compilation (watching sources).
  • mill test to execute the test suite
  • mill assembly to generate uber jar: out/assembly.dest/out.jar

@froth
Copy link
Member

froth commented Feb 17, 2025

Hi, thanks for your work!

I am not necessary against adding another build tool to the template. So this looks fine to me, but I would appreciate opinions from other maintainers.

The one thing that I am unsure about, is whether scala steward can update mill dependencies inside of an g8 template(for sbt this works only if the top level build.sbt file depends on the same libs as the template one). If this does not work, this pull request adds the burden to update dependencies manually. Currently maintaining this template is really low effort and I would like to keep it that way ;)

@carlosrogue
Copy link
Author

carlosrogue commented Feb 17, 2025

@froth sure, I will check the scala steward update of deps because if not this change does not make sense.

UPDATE:
From Scala steward docs regarding Giter 8 templates and Repository-specific configuration having the default config for updates.fileExtensions also includes *.mill files.

@carlosrogue
Copy link
Author

carlosrogue commented Feb 17, 2025

@froth I could not verify Scala Steward run for this but these changes 881f02da might be enough to get automatic dependencies updates in the new build.mill giter8 template file. Shall we give it a try?
The only manual update is the Scala version (scala-steward-org/scala-steward#145) that must be set manually in both build definition files or just re-adding scala_version to g8 template fields, as added here a9fde196f.

UPDATE:
Regarding .mill-version it seems Scala Steward support Automatic mill updates, example MR: ckipp01/mill-giter8#106.

@rossabaker
Copy link
Member

I'm not so sure we want the template to generate two builds. This is potentially confusing to new users, and leaves experienced users one to clean up as a first chore. I could maybe instead see this as a branch, an alternate repo that we link to, or perhaps use g8's conditionals and prompt for which build system to generate.

@carlosrogue
Copy link
Author

carlosrogue commented Feb 17, 2025

@rossabaker very good points. I vote for having a sbt conditional g8 template field:

scala_version [3.3.3]: 
sbt [YES/no] y

sbt template field: Conditional generation of build files is implemented in 1326e2065 however this breaks Scala Steward updates because they are based on file extension, build files are now .sbt$endif$ and .mill$endif$ so adding .scala-steward.conf with content:

updates.fileExtensions = [".mill",".sbt",".sc",".sbt$endif$"`,".mill$endif$","mill-version"]

might configure the update for those conditional files.

@@ -1,3 +1,5 @@
name = quickstart
organization = com.example
package = $organization$.$name;format="norm,word"$

scala_version = 3.3.3
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reverts #420 made by @froth in order to avoid having to change the version in 2 places. I guess is better to remove it, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used Mill, but we've solved the problem of duplicate constants in templates at work with a technique similar to this FAQ. I don't know whether Scala Steward would be able to find a 3.3.3 in a template across SBT and Mill.

I'm good with whatever @froth thinks here. It would be nice if there's one source of truth, but it's also not the worst duplication in the world.

Copy link
Author

@carlosrogue carlosrogue Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is exactly the heuristic I haven't been able to determine, if Scala Steward will update Mill from SBT update dependencies. I will try to configure and run Scala Steward in a repo with some outdated deps,

UPDATE
Already got some trace logs:

2025-02-19 00:13:03,848 INFO  Process update ch.epfl.scala:sbt-bloop : 1.4.12 -> 1.6.0
2025-02-19 00:13:03,864 DEBUG Execute /opt/scala-steward/pass.sh Password for 'https://[email protected]': 
2025-02-19 00:13:04,193 DEBUG Execute git -c core.hooksPath=/dev/null grep -I --fixed-strings --files-with-matches 1.4.12
2025-02-19 00:13:04,208 TRACE project/metals.sbt
2025-02-19 00:13:04,209 TRACE project/project/metals.sbt
2025-02-19 00:13:04,210 TRACE project/project/project/metals.sbt

I am going to remove dependencies until I get one update for both SBT and Mill.
Bingo! Here is the http4s version update. Only build.sbt is being update so I am going to adjust steward config:

2025-02-19 00:28:05,238 INFO  Process update org.http4s:{(http4s-circe, http4s-circe_2.12), (http4s-dsl, http4s-dsl_2.12), (http4s-ember-client, http4s-ember-client_2.12), (http4s-ember-server, http4s-ember-server_2.12)} : 0.23.27 -> 0.23.30
2025-02-19 00:28:05,488 DEBUG Execute git -c core.hooksPath=/dev/null grep -I --fixed-strings --files-with-matches 0.23.27
2025-02-19 00:28:05,498 TRACE build.sbt
2025-02-19 00:28:05,498 TRACE src/main/g8/$if(!sbt.truthy)$build.mill$endif$
2025-02-19 00:28:05,499 TRACE src/main/g8/$if(sbt.truthy)$build.sbt$endif$
2025-02-19 00:28:05,501 TRACE 
2025-02-19 00:28:05,609 DEBUG Execute git -c core.hooksPath=/dev/null grep -I --fixed-strings --files-with-matches org.http4s
2025-02-19 00:28:05,616 TRACE build.sbt
2025-02-19 00:28:05,618 TRACE src/main/g8/$if(!sbt.truthy)$build.mill$endif$
2025-02-19 00:28:05,619 TRACE src/main/g8/$if(sbt.truthy)$build.sbt$endif$
2025-02-19 00:28:05,619 TRACE src/main/g8/src/main/scala/$package__packaged$/$name__Camel$Routes.scala
2025-02-19 00:28:05,620 TRACE src/main/g8/src/main/scala/$package__packaged$/$name__Camel$Server.scala
2025-02-19 00:28:05,620 TRACE src/main/g8/src/main/scala/$package__packaged$/HelloWorld.scala
2025-02-19 00:28:05,620 TRACE src/main/g8/src/main/scala/$package__packaged$/Jokes.scala
2025-02-19 00:28:05,620 TRACE src/main/g8/src/test/scala/$package__packaged$/HelloWorldSpec.scala
2025-02-19 00:28:05,622 TRACE 
2025-02-19 00:28:05,678 INFO  Create branch update/0.23-scala3-mill/http4s-circe-0.23.30
2025-02-19 00:28:05,680 DEBUG Execute git -c core.hooksPath=/dev/null checkout -b update/0.23-scala3-mill/http4s-circe-0.23.30
2025-02-19 00:28:05,687 TRACE Switched to a new branch 'update/0.23-scala3-mill/http4s-circe-0.23.30'
2025-02-19 00:28:05,690 TRACE 
2025-02-19 00:28:05,719 DEBUG Write /opt/scala-steward/workspace/repos/carlosrogue/http4s.g8/build.sbt
2025-02-19 00:28:05,755 DEBUG Execute git -c core.hooksPath=/dev/null status --porcelain --untracked-files=no --ignore-submodules
2025-02-19 00:28:05,765 TRACE  M build.sbt
2025-02-19 00:28:05,768 TRACE 
2025-02-19 00:28:05,784 DEBUG Execute git -c core.hooksPath=/dev/null commit --all --no-gpg-sign --no-signoff -m Update http4s-circe, http4s-dsl, ... to 0.23.30 in 0.23-scala3-mill
2025-02-19 00:28:05,801 TRACE [update/0.23-scala3-mill/http4s-circe-0.23.30 1b5b237] Update http4s-circe, http4s-dsl, ... to 0.23.30 in 0.23-scala3-mill
2025-02-19 00:28:05,804 TRACE  1 file changed, 1 insertion(+), 1 deletion(-)
2025-02-19 00:28:05,806 TRACE 
2025-02-19 00:28:05,810 DEBUG Execute git -c core.hooksPath=/dev/null rev-parse --verify HEAD
2025-02-19 00:28:05,820 TRACE 1b5b237bc35854f0eeda3acfb76742105cfc3316
2025-02-19 00:28:05,822 TRACE 
2025-02-19 00:28:05,877 DEBUG Execute git -c core.hooksPath=/dev/null diff --name-only 0.23-scala3-mill update/0.23-scala3-mill/http4s-circe-0.23.30 --
2025-02-19 00:28:05,883 TRACE build.sbt
2025-02-19 00:28:05,885 TRACE 
2025-02-19 00:28:05,890 INFO  Push 1 commit(s)

ℹ️ configuring Scala Steward file extensions modified the expected files:
updates.fileExtensions = [".sbt",".sc",".scala",".sbt$endif$",".mill$endif$"]
Here is the logs, after custom config 848968a where the 3 giter8 template files were modified:

2025-02-19 00:39:54,349 DEBUG Execute git -c core.hooksPath=/dev/null commit --all --no-gpg-sign --no-signoff -m Update http4s-circe, http4s-dsl, ... to 0.23.30 in 0.23-scala3-mill
2025-02-19 00:39:54,367 TRACE [update/0.23-scala3-mill/http4s-circe-0.23.30 6bbf22f] Update http4s-circe, http4s-dsl, ... to 0.23.30 in 0.23-scala3-mill
2025-02-19 00:39:54,368 TRACE  3 files changed, 3 insertions(+), 3 deletions(-)
2025-02-19 00:39:54,428 DEBUG Execute git -c core.hooksPath=/dev/null diff --name-only 0.23-scala3-mill update/0.23-scala3-mill/http4s-circe-0.23.30 --
2025-02-19 00:39:54,438 TRACE build.sbt
2025-02-19 00:39:54,438 TRACE src/main/g8/$if(!sbt.truthy)$build.mill$endif$
2025-02-19 00:39:54,439 TRACE src/main/g8/$if(sbt.truthy)$build.sbt$endif$
2025-02-19 00:39:54,440 TRACE 
2025-02-19 00:39:54,445 INFO  Push 1 commit(s)

Copy link
Member

@froth froth Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used Mill, but we've solved the problem of duplicate constants in templates at work with a technique similar to this FAQ. I don't know whether Scala Steward would be able to find a 3.3.3 in a template across SBT and Mill.

I'm good with whatever @froth thinks here. It would be nice if there's one source of truth, but it's also not the worst duplication in the world.

Can live with both :) but are are duplicating the dependency versions anyways, so I would prefer it to not be added to the default.properties. That way scala version and dependency versions are handled the same way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree is better to remove it from default.properties.

@carlosrogue carlosrogue force-pushed the 0.23-scala3 branch 2 times, most recently from 7e062c4 to 848968a Compare February 19, 2025 01:01
@froth
Copy link
Member

froth commented Feb 19, 2025

Just now saw that this pull request targets 0.23-scala3. The current workflow is making changes on 0.23 and then merging to 0.23-scala3. This makes maintaining the scala3 template really easy. Could you target 0.23?

@carlosrogue carlosrogue changed the base branch from 0.23-scala3 to 0.23 February 19, 2025 06:55
@carlosrogue carlosrogue changed the base branch from 0.23 to 0.23-scala3 February 19, 2025 07:00
@carlosrogue carlosrogue changed the base branch from 0.23-scala3 to 0.23 February 19, 2025 07:13
@carlosrogue
Copy link
Author

carlosrogue commented Feb 19, 2025

@froth sure, I changed the base to 0.23, going to rebase the branch then.

UPDATE: I rebased the branch.

@froth
Copy link
Member

froth commented Feb 19, 2025

@froth sure, I changed the base to 0.23, going to rebase the branch then.

I think you have to cherry pick (or whatever) your changes to the 0.23 branch. Currently your pull request migrates the 0.23 branch to scala3. Sorry for complicating things :(

@froth
Copy link
Member

froth commented Feb 19, 2025

@rossabaker very good points. I vote for having a sbt conditional g8 template field:

scala_version [3.3.3]: 
sbt [YES/no] y

I am a little unhappy about the usability of this. If someone doesn't know that the template supports mill, they might be confused about what actually happens if you opt out of sbt(and what would happen if we would choose to also support scala-cli?). Maybe a separate branch would be more easy? I am really unsure what would be the easiest solution for the user (and also maintainers).

@carlosrogue carlosrogue force-pushed the 0.23-scala3 branch 3 times, most recently from 3f735dd to 9271708 Compare February 19, 2025 08:59
@carlosrogue
Copy link
Author

carlosrogue commented Feb 19, 2025

@rossabaker very good points. I vote for having a sbt conditional g8 template field:

scala_version [3.3.3]: 
sbt [YES/no] y

I am a little unhappy about the usability of this. If someone doesn't know that the template supports mill, they might be confused about what actually happens if you opt out of sbt(and what would happen if we would choose to also support scala-cli?). Maybe a separate branch would be more easy? I am really unsure what would be the easiest solution for the user (and also maintainers).

@froth what about adding a property per build tool?

sbt [YES/no]: n
mill [yes/NO]: yes

If not then having a separate branch would be O.K.

UPDATE:
Here is the support 4d85053 for build tools properties:

name [quickstart]: mill
organization [com.example]: 
package [com.example.mill]: 
sbt [YES/no]: n
mill [yes/NO]: y

ANOTHER IMPORTANT UPDATE:
@froth adding support for scala-cli build is going to be very easy (implemented here: 4cb7860), I verified ✔️ and Steward update dependencies here also:

2025-02-19 12:14:57,228 INFO  Nurture carlosrogue/http4s.g8:0.23-mill-build
2025-02-19 12:14:57,242 INFO  Found 1 update:
  org.scalameta:(munit, munit_2.12, munit_3) : 1.0.0 -> 1.0.4

2025-02-19 12:14:57,615 DEBUG Execute git -c core.hooksPath=/dev/null grep -I --fixed-strings --files-with-matches 1.0.0
2025-02-19 12:14:57,622 TRACE Http4s.scala
2025-02-19 12:14:57,623 TRACE build.sbt
2025-02-19 12:14:57,624 TRACE src/main/g8/$if(mill.truthy)$build.mill$endif$
2025-02-19 12:14:57,625 TRACE src/main/g8/$if(sbt.truthy)$build.sbt$endif$
2025-02-19 12:14:57,628 TRACE 
2025-02-19 12:14:57,766 DEBUG Execute git -c core.hooksPath=/dev/null grep -I --fixed-strings --files-with-matches org.scalameta
2025-02-19 12:14:57,773 TRACE Http4s.scala
2025-02-19 12:14:57,773 TRACE build.sbt
2025-02-19 12:14:57,774 TRACE src/main/g8/$if(mill.truthy)$build.mill$endif$
2025-02-19 12:14:57,775 TRACE src/main/g8/$if(sbt.truthy)$build.sbt$endif$
2025-02-19 12:14:57,776 TRACE 
2025-02-19 12:14:57,830 INFO  Create branch update/0.23-mill-build/munit-1.0.4

2025-02-19 12:14:57,954 TRACE [update/0.23-mill-build/munit-1.0.4 1189d6f] Update munit to 1.0.4 in 0.23-mill-build
2025-02-19 12:14:57,956 TRACE  4 files changed, 4 insertions(+), 4 deletions(-)

def pomSettings = PomSettings(
description = artifactName(),
organization = "$organization$",
url = "https://http4s.org/v0.23/docs/quickstart.html#giter8-template",
Copy link
Member

@froth froth Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the following lines should be dropped, that's the info from the outer build.sbt and not what we want to generate in the template

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All PomSettings fields are required. The idea was to add support for publishing this dependency as a jar, when removed there is no more publish tasks available (mill publishLocal) and the default output from mill jar is out/jar.dest/out.jar. I am removing it.

@froth
Copy link
Member

froth commented Feb 19, 2025

@froth what about adding a property per build tool?

sbt [YES/no]: n
mill [yes/NO]: yes

If not then having a separate branch would be O.K.

I believe I would actually prefer the separate branch version because it keeps the repo cleaner and in my opinion slighly easier for the user. I am feeling guilty however, because you already invested lot's of effort into this and this would mean throwing away part of of that good work. I really appreciate you contributing and hope this does not comes across overly nitpicky. If you want I can take over from here if you are "done" :)

@carlosrogue
Copy link
Author

@froth what about adding a property per build tool?

sbt [YES/no]: n
mill [yes/NO]: yes

If not then having a separate branch would be O.K.

I believe I would actually prefer the separate branch version because it keeps the repo cleaner and in my opinion slighly easier for the user. I am feeling guilty however, because you already invested lot's of effort into this and this would mean throwing away part of of that good work. I really appreciate you contributing and hope this does not comes across overly nitpicky. If you want I can take over from here if you are "done" :)

@froth what about adding a property per build tool?

sbt [YES/no]: n
mill [yes/NO]: yes

If not then having a separate branch would be O.K.

I believe I would actually prefer the separate branch version because it keeps the repo cleaner and in my opinion slighly easier for the user. I am feeling guilty however, because you already invested lot's of effort into this and this would mean throwing away part of of that good work. I really appreciate you contributing and hope this does not comes across overly nitpicky. If you want I can take over from here if you are "done" :)

@froth no worries, there was a lot of learnings while doing it so no hard feelings, hehehe. If you instruct me on how to create the separate branch, which name, I can publish the separate changes. Also, I agree is a cleaner approach.

@froth
Copy link
Member

froth commented Feb 19, 2025

@froth no worries, there was a lot of learnings while doing it so no hard feelings, hehehe. If you instruct me on how to create the separate branch, which name, I can publish the separate changes. Also, I agree is a cleaner approach.

I created a branch 0.23-mill which is currently on the same commit as 0.23. If you base your pull request against it, it should work. After we merged it, we need another PR against 0.23 which documents it's existence in the Readme.

@carlosrogue carlosrogue changed the base branch from 0.23 to 0.23-mill February 19, 2025 15:39
@carlosrogue
Copy link
Author

@froth I created a branch 0.23-build in my account that will contain all these commit (for future reference). I am going to clean up and publish this MR with mill generation files only.

README.md Outdated
- Scala 2: `sbt new http4s/http4s.g8`
- Scala 3: `sbt new http4s/http4s.g8 --branch 0.23-scala3`
- Java 8: `sbt new http4s/http4s.g8 --branch 0.23-java8`
- Scala 2: `mill -i init http4s/http4s.g8`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Scala 2: `mill -i init http4s/http4s.g8`
- Scala 2: `mill -i init http4s/http4s.g8 --branch 0.23-mill`

README.md Outdated
- Scala 3: `sbt new http4s/http4s.g8 --branch 0.23-scala3`
- Java 8: `sbt new http4s/http4s.g8 --branch 0.23-java8`
- Scala 2: `mill -i init http4s/http4s.g8`
- Scala 3: `mill -i init http4s/http4s.g8 --branch 0.23-scala3`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two won't work as expected I think, remove them?

@froth
Copy link
Member

froth commented Feb 21, 2025

Looks good, thanks for your work. The only thing missing is that the pipeline fails.

val _ = (Test / g8Test).toTask("").value

I am unsure whether we can get this to work for mill, I can live with removing the test for the mill branch if there is no easy solution for this.

@carlosrogue
Copy link
Author

carlosrogue commented Feb 21, 2025

Looks good, thanks for your work. The only thing missing is that the pipeline fails.

val _ = (Test / g8Test).toTask("").value

I am unsure whether we can get this to work for mill, I can live with removing the test for the mill branch if there is no easy solution for this.

Yes, I was working on adding mill support for the main project and fixing CI. I will push those changes when getting a green pipeline. (I am on holidays so out for some weeks).

You could also add a dummy test and I fix it in another PR:

val g8TestMill := taskKey[Unit]("Test generated template for Mill")
// empty project setting
g8TestMill := {} 

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.

3 participants