Properly handle coursier-supported env variables in Mill daemon
Some settings in mill, like COURSIER_REPOSITORIES and COURSIER_CREDENTIALS, are specified as env variables. Env variables are read when a process starts, and later changes to the env variable are invisible to that process.
Since mill automatically starts a background process to avoid paying the startup overhead every time the user types ./mill, users will be confused when they change these variables but they don't take effect. Hence, the mill background process should be restarted if the environment variables have changed since the last time the launcher script was invoked, and perhaps also if the launcher script itself was modified.
Restarting the Mill daemon with every env var change is IMHO overkill. First, the assumption that those change infrequently might not hold for all users. But more importantly, Mill already captures env variable changes and has an API to read up-to-date env variables via Task.env/TaskCtx.Env API. Workers and other long running tasks need to capture those env variables via input tasks (thus making them proper dependencies), and Mill will automatically take care of them, e.g. by restarting the worker. This is properly documented: https://mill-build.org/mill/fundamentals/tasks.html#_environment_variable_inputs
The fact, that the embedded coursier implementation currently ignores dynamic env variable changes is IMHO a bug (or an absent feature), which we should fix.
Hardcoding support for coursier env vars seems fine for now, since those are by far the most common ones people will have trouble with. We can revisit the issue in future if the problem re-emerges with other environment variables
Coursier falls back to read Java system properties, so we could forward the env vars to the respective system properties. It uses coursier.repositories and cursier.credentials. But since the env vars have higher priority, we have the issue that we must clear them before coursier reads them, otherwise the stale env var values still overshadow the up-to-date system properties. But I don't think we can clear env vars programmatically.
We need some API to set these values then.
@alexarchambault could you take a look at this one? This seems like it should be straightforward for someone who is familiar with the coursier codebase and APIs
coursier currently reads a number of env vars and Java properties, that are used to build default values for a number of parameters (default repositories, TTL of snapshots and version listings in cache, …)
I guess reading those via Task.Inputs ought to make Mill aware of their changes. I'm trying that.
Re-opening since the fix got reverted