How to override the classpath order on launch & on assembly #3613
-
In my (currently sbt) project, I sometimes have cases where I need to modify the behavior of a library, or some code I don't control. When I was using sbt, on local run, it seems to specify the project build output classpath before any library jars. This way, if my compiler outputs a class with the same name as one in a jar, the jar ones were shadowed and not used. (I know this feels not nice for some, but there are no alternatives in my case.) Also, sbt-assembly plugin has a strategy called Is it possible to get sbt's behavior here for local runs and assembly? I'm in the middle of a build tool migration and this came up as an unexpected blocker. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Looks like you already know that depending on the order of classpath entries is a call for trouble. I don't recommend to rely on classpath ordering in the long term. That aside, I know from experience that it's sometimes necessary to fiddle with such details. Welcome to Mill, where such customizations are possible and probably much easier in comparison to other build tools. Nevertheless, you should aim to fix these workaround by addressing the root causes. For example by patching and re-packaging the respective thirdparty-library and using these customized artifacts in a standardized and streamlined way. The classpath used to run your module is assembled in mill/scalalib/src/mill/scalalib/JavaModule.scala Lines 557 to 566 in 4c3d2cb You can customize it or follow it's dependencies (navigation features of your IDE should work) and customize those. Either replace the implementation or just apply selective changes with some costom sorter applied to The classpath used for Keep in mind that once you customize such integral targets, you should watch Mill changes closely to be aware of any upstream changes you risk to miss when using your own implementations. Therefore I recommend to first try to customize the output (e.g. by re-ordering the classpath elements based on known paths) instead of replacing the original target definition. |
Beta Was this translation helpful? Give feedback.
-
My questions are all answered, but I actually have a discussion point: if there's classpath conflict, shouldn't the one that originate from the project be preferred? I feel the dependencies having higher priority than compilation output is a bad default. I don't know how many people rely on this (probably undefined) behavior though, so I would of course be careful to change this. |
Beta Was this translation helpful? Give feedback.
Looks like you already know that depending on the order of classpath entries is a call for trouble. I don't recommend to rely on classpath ordering in the long term.
That aside, I know from experience that it's sometimes necessary to fiddle with such details. Welcome to Mill, where such customizations are possible and probably much easier in comparison to other build tools. Nevertheless, you should aim to fix these workaround by addressing the root causes. For example by patching and re-packaging the respective thirdparty-library and using these customized artifacts in a standardized and streamlined way.
The classpath used to run your module is assembled in
runClasspath
.mill/scalalib/…