Open ztlevi opened 3 years ago
Caused by: java.lang.UnsupportedClassVersionError: com/example/junit5/ServiceTest 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
Based on the error, seems like your java is very load. Check M-x shell-command RET java -version
@yyoncho Yeah, M-x shell-command RET java -version
shows
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.282-b08, mixed mode)
But in my terminal, I use jenv to map java executable, and it shows
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.282-b08, mixed mode)
jenv will unset $JAVA_HOME.
Furthermore, I do set lsp-java runtime here https://github.com/ztlevi/doom-config/blob/master/+prog.el#L73-L81. It will give me java 11 for lsp.
My project uses java 11 to compile https://github.com/ztlevi/junit-demo/blob/main/pom.xml#L11-L12
So you are trying to run project compiled with java 11 with java 8...
I don't know why...
M-x shell-command which java
gives me /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/java
which in terminal
junit-demo on main [!+?] is 📦 1.0-SNAPSHOT via ☕ v11.0.10 took 14s
➜ which java
/usr/bin/java
junit-demo on main is 📦 1.0-SNAPSHOT via ☕ v11.0.10
➜ java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
@yyoncho Does dap-mode has special logic to find java executable? Should it respect https://github.com/ztlevi/junit-demo/blob/main/pom.xml#L11-L12?
Use (setq dap-java-java-command "/usr/bin/java")
does not work...
Use (setq dap-java-java-command "/usr/bin/java") does not work...
Do you see the same error? Is /usr/bin/java version 11?
yes, I'm seeing the same error .
junit-demo on main [!+?] is 📦 1.0-SNAPSHOT via ☕ v11.0.10 took 14s
➜ which java
/usr/bin/java
junit-demo on main is 📦 1.0-SNAPSHOT via ☕ v11.0.10
➜ java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
can you post the content of the compilation buffer after you have set the java command?
Sorry, here it is. I didn't attach it because as far as I see, it stills complains about java version....
Anyway, here it is.
Sorry, I have no clue - I mean, clearly the issue is that you are running java 11 compiled stuff with java 8 binary. You have to figure out that on your side. You can run the app in the command line as well.
Running in the terminal gives class not found error...
Running mvn package
works fine :)
junit-demo on main [!?] is 📦 1.0-SNAPSHOT via ☕ v11.0.10 took 2s
➜ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.example:junit-demo >-----------------------
[INFO] Building junit-demo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ junit-demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ junit-demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ junit-demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/ztlevi/dev/junit-demo/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ junit-demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ junit-demo ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.junit5.ParameterExampleTest
1
14
52
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.062 s - in com.example.junit5.ParameterExampleTest
[INFO] Running com.example.junit5.MockitoThrowsTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.804 s - in com.example.junit5.MockitoThrowsTest
[INFO] Running com.example.junit5.ServiceDatabaseIdTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.042 s - in com.example.junit5.ServiceDatabaseIdTest
[INFO] Running com.example.junit5.ServiceTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in com.example.junit5.ServiceTest
[INFO] Running com.example.junit5.TempdirTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.014 s - in com.example.junit5.TempdirTest
[INFO] Running com.example.junit5.MockitoSpyTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in com.example.junit5.MockitoSpyTest
[INFO] Running com.example.junit5.CalculatorTest
[INFO] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.012 s - in com.example.junit5.CalculatorTest
[INFO] Running com.example.junit5.MockitoWhenExampleTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.078 s - in com.example.junit5.MockitoWhenExampleTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 22, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ junit-demo ---
[INFO] Building jar: /Users/ztlevi/dev/junit-demo/target/junit-demo-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.439 s
[INFO] Finished at: 2021-03-27T10:00:01+08:00
[INFO] ------------------------------------------------------------------------
@yyoncho I realized the problem is because I need to configure lsp-java-configuration-runtimes. This is needed by latest jdtls because it doesn't work on Java 8.
But my project is actually using java 8.
Below is my configuration for vscode and it works fine for debugging.
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"default": true,
"path": "/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home"
},
{
"name": "JavaSE-11",
"path": "/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home"
}
],
I tried something like this in Emacs but no luck.
(dolist (java_path '("/usr/lib/jvm/java-11-amazon-corretto.x86_64"
"/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home"))
(if (file-directory-p java_path)
(setq lsp-java-configuration-runtimes `[(:name "JavaSE-11"
:path ,java_path
:default t)
(:name "JavaSE-1.8"
:path "/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home"
)
]
lsp-java-java-path (concat java_path "/bin/java")
)))
Error message
(error "Failed to resolve classpath: The project: OrderThrottlingServiceJavaClient which is referenced by the classpath, does not exist.")
car: Wrong type argument: listp, #("LSP :: `workspace/executeCommand' with `vscode.java.resolveClasspath' failed.
(error \"Failed to resolve classpath: The project: OrderThrottlingServiceJavaClient which is referenced by the classpath, does not exist.\")" 0 3 (face error))
SPC C-d is undefined
I assigned JUNIT_CLASS_PATH as below
export JUNIT_CLASS_PATH=/Users/ztlevi/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.7.0
. Which contains following jar. But running(dap-java-run-test-class)
still pops error.Is this something we need to config? I am confused. It should be able to find the junit jar via package manager.
Backtrace
-*- mode: dap-server-log; default-directory: "~/dev/junit-demo/" -*- Debug Adapter started at Fri Mar 26 20:07:01 java -jar /Users/ztlevi/.config/emacs/.local/etc/lsp/eclipse.jdt.ls/test-runner/junit-platform-console-standalone.jar -cp $JUNIT_CLASS_PATH -m com.example.junit5.ServiceTest#testQuery Thanks for using JUnit! Support its development at https://junit.org/sponsoring Usage: ConsoleLauncher [-h] [--disable-ansi-colors] [--disable-banner] [--fail-if-no-tests] [--scan-modules] [--scan-classpath[=PATH[;|: PATH...]]]... [--details=MODE] [--details-theme=THEME] [--reports-dir=DIR] [-c=CLASS]... [--config=KEY=VALUE]... [-cp=PATH [;|:PATH...]]... [-d=DIR]... [-e=ID]... [-E=ID]... [--exclude-package=PKG]... [-f=FILE]... [--include-package=PKG]... [-m=NAME]... [-n=PATTERN]... [-N=PATTERN]... [-o=NAME]... [-p=PKG]... [-r=RESOURCE]... [-t=TAG]... [-T=TAG]... [-u=URI]... Launches the JUnit Platform from the console. -h, --help Display help information. --disable-ansi-colors Disable ANSI colors in output (not supported by all terminals). --disable-banner Disable print out of the welcome message. --details=MODE Select an output details mode for when tests are executed. Use one of: none, summary, flat, tree, verbose. If 'none' is selected, then only the summary and test failures are shown. Default: tree. --details-theme=THEME Select an output details tree theme for when tests are executed. Use one of: ascii, unicode. Default: unicode. -cp, --classpath, --class-path=PATH[;|:PATH...] Provide additional classpath entries -- for example, for adding engines and their dependencies. This option can be repeated. --fail-if-no-tests Fail and return exit status code 2 if no tests are found. --reports-dir=DIR Enable report output into a specified local directory (will be created if it does not exist). --scan-modules EXPERIMENTAL: Scan all resolved modules for test discovery. -o, --select-module=NAME EXPERIMENTAL: Select single module for test discovery. This option can be repeated. --scan-classpath, --scan-class-path[=PATH[;|:PATH...]] Scan all directories on the classpath or explicit classpath roots. Without arguments, only directories on the system classpath as well as additional classpath entries supplied via -cp (directories and JAR files) are scanned. Explicit classpath roots that are not on the classpath will be silently ignored. This option can be repeated. -u, --select-uri=URI Select a URI for test discovery. This option can be repeated. -f, --select-file=FILE Select a file for test discovery. This option can be repeated. -d, --select-directory=DIR Select a directory for test discovery. This option can be repeated. -p, --select-package=PKG Select a package for test discovery. This option can be repeated. -c, --select-class=CLASS Select a class for test discovery. This option can be repeated. -m, --select-method=NAME Select a method for test discovery. This option can be repeated. -r, --select-resource=RESOURCE Select a classpath resource for test discovery. This option can be repeated. -n, --include-classname=PATTERN Provide a regular expression to include only classes whose fully qualified names match. To avoid loading classes unnecessarily, the default pattern only includes class names that begin with "Test" or end with "Test" or "Tests". When this option is repeated, all patterns will be combined using OR semantics. Default: [^(Test.*|.+[.$] Test.*|.*Tests?)$] -N, --exclude-classname=PATTERN Provide a regular expression to exclude those classes whose fully qualified names match. When this option is repeated, all patterns will be combined using OR semantics. --include-package=PKG Provide a package to be included in the test run. This option can be repeated. --exclude-package=PKG Provide a package to be excluded from the test run. This option can be repeated. -t, --include-tag=TAG Provide a tag or tag expression to include only tests whose tags match. When this option is repeated, all patterns will be combined using OR semantics. -T, --exclude-tag=TAG Provide a tag or tag expression to exclude those tests whose tags match. When this option is repeated, all patterns will be combined using OR semantics. -e, --include-engine=ID Provide the ID of an engine to be included in the test run. This option can be repeated. -E, --exclude-engine=ID Provide the ID of an engine to be excluded from the test run. This option can be repeated. --config=KEY=VALUE Set a configuration parameter for test discovery and execution. This option can be repeated. org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:189) at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:168) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132) at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:66) at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$0(ConsoleTestExecutor.java:58) at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.replaceThreadContextClassLoaderAndInvoke(CustomContextClassLoaderExecutor.java:41) at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:31) at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:58) at org.junit.platform.console.ConsoleLauncher.executeTests(ConsoleLauncher.java:95) at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:73) at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:50) at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:43) at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:37) Caused by: org.junit.platform.commons.JUnitException: MethodSelector [className = 'com.example.junit5.ServiceTest', methodName = 'testQuery', methodParameterTypes = ''] resolution failed at org.junit.platform.launcher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnFailureLauncherDiscoveryListener.java:39) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:102) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:82) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113) at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:45) at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69) at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:181) ... 12 more Caused by: java.lang.UnsupportedClassVersionError: com/example/junit5/ServiceTest 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:756) 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:418) at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:817) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) at org.junit.platform.commons.util.ReflectionUtils.lambda$tryToLoadClass$9(ReflectionUtils.java:790) at org.junit.platform.commons.function.Try.lambda$call$0(Try.java:57) at org.junit.platform.commons.function.Try.of(Try.java:93) at org.junit.platform.commons.function.Try.call(Try.java:57) at org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass(ReflectionUtils.java:753) at org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass(ReflectionUtils.java:709) at org.junit.platform.engine.discovery.MethodSelector.lazyLoadJavaClass(MethodSelector.java:156) at org.junit.platform.engine.discovery.MethodSelector.getJavaClass(MethodSelector.java:135) at org.junit.jupiter.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:69) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:146) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1361) at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126) at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:531) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:185) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:125) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:91) ... 17 more Debug Adapter exited abnormally with code 255 at Fri Mar 26 20:07:01