Created
May 16, 2021 17:05
-
-
Save rtyley/ee31ee962be024a5f71fb1ff836f8d72 to your computer and use it in GitHub Desktop.
Code compiled with Scala 3.0.0 throws NoClassDefFoundError/ClassNotFoundException when tests run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[info] Setting Scala version to 2.13.5 on 1 projects. | |
[info] Reapplying settings... | |
[info] set current project to scala-2-vs-3-noclassdeffounderror (in build file:/home/roberto/development/scala-2-vs-3-NoClassDefFoundError/) | |
[info] ExampleSpec: | |
[info] using Java Compress library | |
[info] - should not throw java.lang.NoClassDefFoundError | |
[info] Run completed in 302 milliseconds. | |
[info] Total number of tests run: 1 | |
[info] Suites: completed 1, aborted 0 | |
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0 | |
[info] All tests passed. | |
[success] Total time: 1 s, completed 16 May 2021, 18:03:33 | |
[info] Setting Scala version to 3.0.0 on 1 projects. | |
[info] Reapplying settings... | |
[info] set current project to scala-2-vs-3-noclassdeffounderror (in build file:/home/roberto/development/scala-2-vs-3-NoClassDefFoundError/) | |
[info] ExampleSpec: | |
[info] using Java Compress library | |
[info] com.madgag.example.ExampleSpec *** ABORTED *** | |
[info] java.lang.NoClassDefFoundError: com/madgag/compress/CompressUtil$ | |
[info] at com.madgag.example.ExampleSpec.testFun$proxy1$1(ExampleSpec.scala:8) | |
[info] at com.madgag.example.ExampleSpec.$init$$$anonfun$1(ExampleSpec.scala:8) | |
[info] at org.scalatest.Transformer.apply$$anonfun$1(Transformer.scala:22) | |
[info] at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85) | |
[info] at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:31) | |
[info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104) | |
[info] at org.scalatest.Transformer.apply(Transformer.scala:22) | |
[info] at org.scalatest.Transformer.apply(Transformer.scala:21) | |
[info] at org.scalatest.flatspec.AnyFlatSpecLike$$anon$4.apply(AnyFlatSpecLike.scala:1697) | |
[info] at org.scalatest.TestSuite.withFixture(TestSuite.scala:196) | |
[info] ... | |
[info] Cause: java.lang.ClassNotFoundException: com.madgag.compress.CompressUtil$ | |
[info] at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471) | |
[info] at sbt.internal.ManagedClassLoader.findClass(ManagedClassLoader.java:102) | |
[info] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589) | |
[info] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) | |
[info] at com.madgag.example.ExampleSpec.testFun$proxy1$1(ExampleSpec.scala:8) | |
[info] at com.madgag.example.ExampleSpec.$init$$$anonfun$1(ExampleSpec.scala:8) | |
[info] at org.scalatest.Transformer.apply$$anonfun$1(Transformer.scala:22) | |
[info] at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85) | |
[info] at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:31) | |
[info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104) | |
[info] ... | |
[error] Test suite com.madgag.example.ExampleSpec failed with java.lang.NoClassDefFoundError: com/madgag/compress/CompressUtil$. | |
[error] This may be due to the ClassLoaderLayeringStrategy (ScalaLibrary) used by your task. | |
[error] To improve performance and reduce memory, sbt attempts to cache the class loaders used to load the project dependencies. | |
[error] The project class files are loaded in a separate class loader that is created for each test run. | |
[error] The test class loader accesses the project dependency classes using the cached project dependency classloader. | |
[error] With this approach, class loading may fail under the following conditions: | |
[error] | |
[error] * Dependencies use reflection to access classes in your project's classpath. | |
[error] Java serialization/deserialization may cause this. | |
[error] * An open package is accessed across layers. If the project's classes access or extend | |
[error] jvm package private classes defined in a project dependency, it may cause an IllegalAccessError | |
[error] because the jvm enforces package private at the classloader level. | |
[error] | |
[error] These issues, along with others that were not enumerated above, may be resolved by changing the class loader layering strategy. | |
[error] The Flat and ScalaLibrary strategies bundle the full project classpath in the same class loader. | |
[error] To use one of these strategies, set the ClassLoaderLayeringStrategy key | |
[error] in your configuration, for example: | |
[error] | |
[error] set scala-2-vs-3-noclassdeffounderror / Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.ScalaLibrary | |
[error] set scala-2-vs-3-noclassdeffounderror / Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat | |
[error] | |
[error] See ClassLoaderLayeringStrategy.scala for the full list of options. | |
[info] Run completed in 264 milliseconds. | |
[info] Total number of tests run: 0 | |
[info] Suites: completed 0, aborted 1 | |
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0 | |
[info] *** 1 SUITE ABORTED *** | |
[error] Error during tests: | |
[error] com.madgag.example.ExampleSpec | |
[error] (Test / test) sbt.TestsFailedException: Tests unsuccessful | |
[error] Total time: 2 s, completed 16 May 2021, 18:03:35 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment