1919import mill .constants .CodeGenConstants ;
2020import mill .constants .DaemonFiles ;
2121import mill .constants .EnvVars ;
22+ import scala .None ;
23+ import scala .None$ ;
24+ import scala .Option$ ;
2225
2326public class MillProcessLauncher {
2427
@@ -120,11 +123,11 @@ static List<String> loadMillConfig(String key) throws Exception {
120123 Object conf = mill .launcher .ConfigReader .readYaml (
121124 buildFile , buildFile .getFileName ().toString ());
122125 if (!(conf instanceof Map )) return new String [] {};
123- Map <String , Object > conf2 = (Map <String , Object >) conf ;
126+ @ SuppressWarnings ( "unchecked" ) Map <String , Object > conf2 = (Map <String , Object >) conf ;
124127
125128 if (!conf2 .containsKey (key )) return new String [] {};
126129 if (conf2 .get (key ) instanceof List ) {
127- List <String > list = (List <String >) conf2 .get (key );
130+ @ SuppressWarnings ( "unchecked" ) List <String > list = (List <String >) conf2 .get (key );
128131 String [] arr = new String [list .size ()];
129132 for (int i = 0 ; i < arr .length ; i ++) {
130133 arr [i ] = mill .constants .Util .interpolateEnvVars (list .get (i ), env );
@@ -152,7 +155,15 @@ static List<String> millOpts() throws Exception {
152155 }
153156
154157 static String millJvmVersion () throws Exception {
155- List <String > res = loadMillConfig ("mill-jvm-version" );
158+ return loadMillConfigSingleValue ("mill-jvm-version" );
159+ }
160+
161+ static String millScalaLibraryVersion () throws Exception {
162+ return loadMillConfigSingleValue ("mill-scala-library-version" );
163+ }
164+
165+ static String loadMillConfigSingleValue (String key ) throws Exception {
166+ List <String > res = loadMillConfig (key );
156167 if (res .isEmpty ()) return null ;
157168 else return res .get (0 );
158169 }
@@ -228,10 +239,16 @@ static List<String> millLaunchJvmCommand() throws Exception {
228239 // extra opts
229240 vmOptions .addAll (millJvmOpts ());
230241
242+ var maybeScalaLibraryVersion = millScalaLibraryVersion ();
231243 vmOptions .add ("-XX:+HeapDumpOnOutOfMemoryError" );
232244 vmOptions .add ("-cp" );
245+ var classPathCacheKey =
246+ "mill:" + BuildInfo .millVersion +
247+ ",scala-library-version:" + (maybeScalaLibraryVersion == null ? "default" : maybeScalaLibraryVersion );
233248 String [] runnerClasspath = cachedComputedValue0 (
234- "resolve-runner" , BuildInfo .millVersion , () -> CoursierClient .resolveMillDaemon (), arr -> {
249+ "resolve-runner" , classPathCacheKey ,
250+ () -> CoursierClient .resolveMillDaemon (Option$ .MODULE$ .apply (maybeScalaLibraryVersion )),
251+ arr -> {
235252 for (String s : arr ) {
236253 if (!Files .exists (Paths .get (s ))) return false ;
237254 }
@@ -246,6 +263,19 @@ static String[] cachedComputedValue(String name, String key, Supplier<String[]>
246263 return cachedComputedValue0 (name , key , block , arr -> true );
247264 }
248265
266+ /**
267+ * Loads a value from the cache, or computes it if it's not in the cache, or re-computes it if it's
268+ * in the cache but invalid.
269+ * <p>
270+ * The cache is stored in the `out/mill-{name}` file and contains only a single key.
271+ *
272+ * @param name name of the cached value
273+ * @param key key of the value in the cache. If the cache exists but the key doesn't match, the value
274+ * will be re-computed.
275+ * @param block block to compute the value
276+ * @param validate function to validate the value. If the value is in cache but invalid, it will be
277+ * re-computed.
278+ */
249279 static String [] cachedComputedValue0 (
250280 String name , String key , Supplier <String []> block , Function <String [], Boolean > validate ) {
251281 try {
0 commit comments