sbt-1.3.0-M2 breaks code that relies on URLClassLoader
See original GitHub issue- I’ve read the CONTRIBUTING guidelines
steps
- Checkout airfame https://github.com/wvlet/airframe
- Run
sbt -Dsbt.version=1.3.0-M2 logJVM/testOnly *ResourceTest
problem
-
Some application needs to find files inside a jar file. To do so, we need to use the public method
URLClassLoader.findResourceURLs(path) : Enumeration[URL]
. ClassLoader has the same name method, but it’s defined as protected, so we cannot use the base ClassLoader. -
Before sbt-1.3.0-M2, if we trace parent class loaders, we usually can find at least one URLClassLoader that can access resources inside jar files.
- Actually LayeredClassLoader, which is extending URLClassLoader, is found as a parent class loader, but it seems this class loader cannot find resources inside jar files.
-
Upgrading airframe to use sbt-1.3.0-M2 breaks the build https://github.com/wvlet/airframe/pull/457
- This is because no URLClassLoader that can find resources inside jar files can be found in this code: https://github.com/wvlet/airframe/blob/28a70c3fdc7a209eabf357548bdf7737c80e7b52/airframe-log/jvm/src/main/scala/wvlet/log/io/Resource.scala#L81-L90
expectation
- sbt class loader should provide a URLClassLoader to get local resource URls.
notes
sbt version: 1.3.0-M2
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (17 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Should be fixed in #4601
Ok, cool. I didn’t fully understand the use case. My point is simply that there is nothing in the sbt spec that says that run or test provide any specific URLClassLoader implementation so you are relying on undefined behavior. As long as we can agree on that point (or agree to disagree), I think we can move on.
I’m not saying you’re wrong. I am suggesting that if a URLClassLoader with specific semantics is required then it would be best practice to actually manage your classloaders manually and not rely on what sbt provides by default. Then you will not be impacted if sbt (or any other build tool) changes the implementation out from underneath you.
Again, I am planning to fix the current airframe build before sbt 1.3.0.