java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to scala.collection.Seq during runAll

Hi,

We use mvn lagom:runAll with 1.6.0-M2 plugin version for development, and the following error occurs during startup at com.lightbend.lagom.maven.RunAllMojo.$anonfun$execute$15 (ServiceMojos.scala:402)

Failed to execute goal com.lightbend.lagom:lagom-maven-plugin:1.6.0-M2:runAll (default-cli) on project customer: A type incompatibility occurred while executing com.lightbend.lagom:lagom-maven-plugin:1.6.0-M2:runAll: scala.collection.immutable.$colon$colon cannot be cast to scala.collection.Seq

[…]

import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:199)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to scala.collection.Seq
    at scala.Option.map (Option.scala:163)
    at com.lightbend.lagom.maven.RunAllMojo.$anonfun$execute$15 (ServiceMojos.scala:402)
    at scala.collection.TraversableLike.$anonfun$map$1 (TraversableLike.scala:237)
    at scala.collection.mutable.ResizableArray.foreach (ResizableArray.scala:62)
    at scala.collection.mutable.ResizableArray.foreach$ (ResizableArray.scala:55)
    at scala.collection.mutable.ArrayBuffer.foreach (ArrayBuffer.scala:49)
    at scala.collection.TraversableLike.map (TraversableLike.scala:237)
    at scala.collection.TraversableLike.map$ (TraversableLike.scala:230)
    at scala.collection.AbstractTraversable.map (Traversable.scala:108)
    at com.lightbend.lagom.maven.RunAllMojo.execute (ServiceMojos.scala:399)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

This consistently happens on one developer’s machine, for the others, it works fine all the time. What could cause this behaviour? We tried deleting the scala-lang dependencies from the local maven repo, and redownloaded it, but the problem still exists.

1 Like

It is turned out with further testing, and “debugging”, that the problem is really the different classloaders.
And now it is not for one developer, but most of it… David is on holiday, actually he said it was working on his machine…
Now the question is, why?

So we have the same structure as the hello world lagom sample application, an api and an impl maven module under the root pom artifact.

During execution, there will be two ClassRealm for the lagom plugin.
1., The Option holds a :: from this realm:

-----------------------------------------------------
realm = plugin>com.lightbend.lagom:lagom-maven-plugin:1.6.0-M2-1042173423
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/.m2/repository/com/lightbend/lagom/lagom-maven-plugin/1.6.0-M2/lagom-maven-plugin-1.6.0-M2.jar
urls[1] = file:/C:/.m2/repository/org/scala-lang/scala-library/2.12.8/scala-library-2.12.8.jar
…
Number of foreign imports: 1
import: Entry[import from realm ClassRealm[project>xxxx.xxxx:xxxx-api:1.0.0-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]
-----------------------------------------------------

2., The current executing class realm:
-----------------------------------------------------
realm = plugin>com.lightbend.lagom:lagom-maven-plugin:1.6.0-M2
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/.m2/repository/com/lightbend/lagom/lagom-maven-plugin/1.6.0-M2/lagom-maven-plugin-1.6.0-M2.jar
urls[1] = file:/C:/.m2/repository/org/scala-lang/scala-library/2.12.8/scala-library-2.12.8.jar
…
Number of foreign imports: 1
import: Entry[import from realm ClassRealm[maven.api, parent: null]]
-----------------------------------------------------

Check the differences. It can be some kind of Maven problem.

This is where we are now.

-- Vazul

1 Like

Solved…

The impl maven module contains a plugin, with <extensions>true</extensions>. I don’t know why, but it is a protobuf maven plugin, and we do not need the extensions flag (add protoc to the toolchain?), so after all it is working again.
That plugin was causing the problem:

<plugin>
	<groupId>org.xolstice.maven.plugins</groupId>
	<artifactId>protobuf-maven-plugin</artifactId>
	<version>${protobuf.plugin.version}</version>

<!-- this is removed: <extensions>true</extensions> -->

	<configuration>
		<protocArtifact>com.google.protobuf:protoc:3.8.0:exe:${os.detected.classifier}</protocArtifact>
	</configuration>
	<executions>
		<execution>
			<goals>
				<goal>compile</goal>
			</goals>
		</execution>
	</executions>
</plugin>
1 Like