JetBrains / sbt-idea-plugin

Develop IntelliJ plugins with Scala and SBT
Apache License 2.0
98 stars 28 forks source link

NoClassDefFoundError when running in test after upgrading to 3.9.x #91

Closed nevillelyh closed 3 years ago

nevillelyh commented 3 years ago

After upgrading from 3.8.5 to 3.9.1 (and a few other things due to Scala 2.12->2.13) my test stopped working with a NoClassDefFoundError. It seems the Test scope no longer includes Compile classes. I tried the common sbt tricks like fork or layering strategy but none worked.

This is the breaking commit: https://github.com/spotify/scio-idea-plugin/commit/31a386ad8c9d5e05f3339488f09bb047f6a56c5b

[info] compiling 3 Scala sources to /home/neville/src/spotify/scio-idea-plugin/target/scala-2.13/classes ...
[info] compiling 1 Scala source to /home/neville/src/spotify/scio-idea-plugin/target/scala-2.13/test-classes ...
[info] ScioInjectorTest:
[info] Tupled method
[info] com.spotify.scio.ScioInjectorTest *** ABORTED ***
[info]   java.lang.NoClassDefFoundError: com/spotify/scio/AnnotationTypeInjector$
[info]   at com.spotify.scio.ScioInjectorTest.$anonfun$new$1(ScioInjectorTest.scala:31)
[info]   at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
[info]   at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
[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:20)
[info]   at org.scalatest.flatspec.AnyFlatSpecLike$$anon$5.apply(AnyFlatSpecLike.scala:1684)
[info]   at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
[info]   at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
[info]   at org.scalatest.flatspec.AnyFlatSpec.withFixture(AnyFlatSpec.scala:1685)
[info]   ...
[info]   Cause: java.lang.ClassNotFoundException: com.spotify.scio.AnnotationTypeInjector$
[info]   at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
[info]   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
[info]   at com.spotify.scio.ScioInjectorTest.$anonfun$new$1(ScioInjectorTest.scala:31)
[info]   at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
[info]   at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
[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:20)
mutcianm commented 3 years ago

IJ plugin classloading in tests is handled by the IJ test framework, not SBT. The reason you're getting this error is that IJ cannot find plugins jars because the plugin artifact hasn't been assembled. sbt-idea-plugin adds a dependency on packageArtifact task to the testOnly task. However, turns out I somehow missed that sbt's test task itself does not depend on testOnly and since you've been running test task as a part of the CI, the artifact was not built.

I'll fix the test test task in the 3.9.2 which I'm planning to publish later today.

nevillelyh commented 3 years ago

Ah yeah that explains why it worked after packagePluginZip. Thanks!