I opened a Gradle Spring boot project in VS Code, and it picked up all the unit tests as expected. Most of the tests run without any problems, but for the ones using the embedded database as I get this error:
org.springframework.dao.InvalidDataAccessApiUsageException: For queries with named parameters you need to use provide names for method parameters. Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters.
Both the problem and the solution are pretty clear from the error, but I’d prefer not to set @Param everywhere and I can’t figure out how to set this flag in VS Code when I’m running the tests. Is it possible to set javac flags in VS Code, and if so how do I do it?
I’ve tried adding several variations on the following to settings.json, without success:
"java.test.config": {
"args": ["parameters"]
}
These tests work fine if I run them with gradle test
or in IntelliJ.
2
Answers
The
-parameters
should be the argument passed to Java Compiler, you can follow this guide: https://github.com/redhat-developer/vscode-java/wiki/Settings-Global-Preferencesjava.settings.url
pointing to the.prefs
file. (You can create it wherever you want).prefs
file, add following line:org.eclipse.jdt.core.compiler.codegen.methodParameters=generate