i have written a Spring Boot Application which should use H2 during development and mariadb for integration tests and production. For developing i use Visual Studio Code in WSL2 with Java Extensions.
In pom.xml i defined H2 repository as dependency:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>test</scope>
</dependency>
In VSCode i created the 3 launch configurations "Debug", "Debug (test)" and "Debug (prod)". In the launch.json file i defined 3 different spring profiles for the different database configurations. Here is an example for the "test" configuration:
{
"type": "java",
"name": "Debug (test)",
"request": "launch",
"mainClass": "de.frickeldave.fleckerlteppich.telemetry.TelemetryApplication",
"preLaunchTask": "startmariadb",
"postDebugTask": "stopmariadb",
"args": "--spring.profiles.active=test"
}
The problem:
When i start my normal "Debug" Configuration in VSCode, i want to use the H2 database. But because of the definition <scope>test</test>
the dependency is not loaded and the application fails to connect. It works perfectly, when i remove the "test-scope" declaration (which is not the goal).
What can i do do start the Application in test scope, to have H2 available when debugging with VSCode? Is there a start-parameter i can add?
Thanks in advance
Regards Dave
Dependencies of scope
test
are not available at runtime.They can only be used for tests that run during the build.