scalatest / scalatest-maven-plugin

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

Make the plugin toolchains aware #58

Open martin-g opened 5 years ago

martin-g commented 5 years ago

Could this plugin be made aware of Maven toolchains so that it use the configured JDK in the project ?

My project defines that it should be build (via maven-toolchains-plugin) with JDK 11 but I run mvn on the command line where JAVA_HOME points to JDK 8 installation and this leads to an error like:

...
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ wicketstuff-scala ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/home/martin/devel/jdk-11/]
[INFO] No sources to compile
[INFO] 
[INFO] --- scala-maven-plugin:3.4.4:testCompile (test-compile) @ wicketstuff-scala ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ wicketstuff-scala ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- scalatest-maven-plugin:2.0.0:test (test) @ wicketstuff-scala ---
Discovery starting.
*** RUN ABORTED ***
  java.lang.UnsupportedClassVersionError: org/apache/wicket/ajax/markup/html/AjaxFallbackLink has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
  at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
  at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  ...
[INFO] ------------------------------------------------------------------------

Information how a Maven plugin could be made toolchains-aware could be found at: https://cwiki.apache.org//confluence/display/MAVENOLD/Toolchains Here is how scala-maven-plugin does it: https://github.com/davidB/scala-maven-plugin/search?q=ToolchainManager&unscoped_q=ToolchainManager

axiopisty commented 4 years ago

We're running into this same issue in our CI/CD pipeline. We use Jenkins to build, test, and deploy our application. The jenkins servers have one version of Java installed on the machine, but the build is allowed to specify which version of the build tools should be used (ie: Java, Maven, etc.).

Currently the Jenkins servers have Java 8 installed, but when we specify to build with Java 11 (probably using docker containers) Maven and all the other plugins we use in our project appropriately use Java 11. The scalatest-maven-plugin does not use Java 11 when it forks. The command it uses is simply java. In this case, I think the problem is that java on the path is pointing to Java 8, but $JAVA_HOME within the build environment specifies Java 11.

I could have some details wrong here because I don't work on our CI/CD team that manages the pipeline, but this is probably a fair analysis of what is happening. We're getting the exact same error as reported here.

blast-hardcheese commented 4 years ago

Related, https://github.com/scalatest/scalatest/issues/297, just discovered this as well

kasabov commented 3 years ago

I was faced with the same issue until I upgraded to latest scalatest-maven-plugin:2.0.2.