scalatest / scalatest-maven-plugin

ScalaTest Maven Plugin
Apache License 2.0
34 stars 61 forks source link

scalatest 2.2.1 with htmlreporters fails with NoClassDefFoundError #11

Open leachbj opened 9 years ago

leachbj commented 9 years ago

Using the plugin with scalatest 2.2.1 and htmlreporters enabled results in a NoClassDefFoundError failure (and a plugin hang).

[INFO] --- scalatest-maven-plugin:1.0:test (test) @ platformtest --- An exception or error caused a run to abort. This may have been caused by a problematic custom reporter. java.lang.NoClassDefFoundError: org/pegdown/PegDownProcessor at org.scalatest.tools.HtmlReporter.(HtmlReporter.scala:115) at org.scalatest.tools.ReporterFactory.createHtmlReporter(ReporterFactory.scala:182) at org.scalatest.tools.ReporterFactory.getReporterFromConfiguration(ReporterFactory.scala:233) at org.scalatest.tools.ReporterFactory$$anonfun$createReportersFromConfigurations$1.apply(ReporterFactory.scala:242) at org.scalatest.tools.ReporterFactory$$anonfun$createReportersFromConfigurations$1.apply(ReporterFactory.scala:241) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245) at scala.collection.Iterator$class.foreach(Iterator.scala:743) at scala.collection.AbstractIterator.foreach(Iterator.scala:1177) at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:43) at scala.collection.TraversableLike$class.map(TraversableLike.scala:245) at org.scalatest.tools.ReporterConfigurations.map(ReporterConfiguration.scala:43) at org.scalatest.tools.ReporterFactory.createReportersFromConfigurations(ReporterFactory.scala:241) at org.scalatest.tools.ReporterFactory.getDispatchReporter(ReporterFactory.scala:245) at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2720) at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043) at org.scalatest.tools.Runner$.main(Runner.scala:860) at org.scalatest.tools.Runner.main(Runner.scala) Caused by: java.lang.ClassNotFoundException: org.pegdown.PegDownProcessor at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 19 more

leachbj commented 9 years ago

Its possible to work around this issue by adding the pegdown dependency to the project running the tests like;

<build>
     <dependencies>
            <dependency>
                    <groupId>org.pegdown</groupId>
                    <artifactId>pegdown</artifactId>
                    <version>1.4.2</version>
                    <scope>test</scope>
            </dependency>
     </dependencies>
</build>

But its not possible to add this dependency to the plugin directly.

bvenners commented 9 years ago

We usually think of pegdown as an optional dependency that you add if you are using the HTML reporter, as a way to minimize dependencies. I don't know of a way to make this automatic other than making it a required dependencey of ScalaTest no matter whether you're using the HTML reporter or not. We could certainly improve the documentation I think, but do you have any other suggestion?

leachbj commented 9 years ago

Not sure if that patchset is an optimal way to support that type of dependency processing in a plugin but it works ;) When pegdown is added it and all its transient dependencies will be added to the classpath.

kostya-sh commented 8 years ago

I agree that pegdown should be included as plugin dependency. Asking users to add pegdown dependency to their poms with scope=test is ugly IMHO. It is better when things just work out of the box. Maven doesn't mix plugin dependencies and project dependencies, so there is no reason to minimize the plugin dependencies and make user experience worse.

bvenners commented 8 years ago

The trouble with a plain old dependency is when someone's project depends on a different version of pegdown it can conflict. That's why I've tried to minimize having any dependencies at all for ScalaTest. What we are considering is to "shade" pegdown during our build: make a new jar that is just a copy of the pegdown binaries that has a different package name, then do a hard-coded dependency on that. Would that satisfy your needs?

kostya-sh commented 8 years ago

Is it possible to make pegdown a dependency of scalatest-maven-plugin only (but not scalatest)? This would be the best solution as a plugin dependencies cannot conflict with project dependencies that use the plugin.

kostya-sh commented 8 years ago

Shaded dependency will work as well.

cvakiitho commented 7 years ago

btw, this also creates an issue reported here: https://groups.google.com/forum/#!topic/scalatest-users/Szk1Utpuv8I so if something in your project uses ASM<4 you should use pegdown 1.1.0:

<dependency>
        <groupId>org.pegdown</groupId>
        <artifactId>pegdown</artifactId>
        <version>1.1.0</version>
        <scope>test</scope>
</dependency>
ldeck commented 3 years ago

Where is the dependency for pegdown and/or flexmark documented? And how does one know what version is compatible?

There’s no mention of it on Using the ScalaTest Maven Plugin page.