skip to Main Content

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


  1. 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-Preferences

    1. Set the setting java.settings.url pointing to the .prefs file. (You can create it wherever you want)
    2. In the .prefs file, add following line:
    org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
    
    Login or Signup to reply.
    1. Select VSCode -> File -> Preferences -> Settings Open Setting page (Either User or Workspace)
    2. Type in "url" filter out and Find Java > Settings:URL:
    3. Type in Java Setting file path/name (Ex: D:java.settings)
    4. Edit Java Setting file (D:java.settings) and Add following line:

    org.eclipse.jdt.core.compiler.codegen.methodParameters=generate

    1. Re-Build Code, should be OK now.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search