You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tests that pass via "mvn test" fail when run from VS Code, seemingly because it isn't executing the Maven Surefire plugin to remove some run-time dependencies from the test classpath.
Background:
The SLF4J folks officially recommend using this testing SLF4J implementation for unit tests: http://projects.lidalia.org.uk/slf4j-test/
Because SLF4J doesn't like multiple implementations, the test library asks you to use the Maven Surefire plugin to remove logback (or whatever SLF4J implementation) from the test classpath (see link).
This works fine when I run tests from the Maven CLI ("mvn test"), but I get a "Class path contains multiple SLF4J bindings" error when trying to run the tests from VS Code.
parkertomatoes it is "mvn test" that executes the maven plugin to remove logback from the test classpath. If I understand it correctly, you want to the ability to configure some preprocess action before runner running the tests? Currently we don't support this.
I also have some similar problems. We use protocolbuffer definitions that generate java source files that are included in the tests. They are not picked up when using this plugin.
we event try to add it to the test class path like so (this is not needed for mvn test to work).
<plugin>
<!-- a hint for IDE's to add the java sources to the classpath -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>01-add-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/protobuf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
parkertomatoesIzak Marais (@IzakMarais) we'll support test configuration this release, where you can configure prelanchTask to execute maven goals, what do you think about this?
I'm not sure the preLaunchTask is what is wanted for this. I've put in a preLaunchTask to call 'mvn test' but that just runs all my tests through maven before attempting to run one test through Code.
Dann Ormond (@dannormond) does your pom.xml contain customized goal execution in or before "test" phase? If so, you could add script like mvn groupID:artifactID:version:goal in the preLaunchTask to achieve the same effect with maven test.
Running tests via Maven CLI works perfectly fine, but when executed in vscode, these fail with messages similar to this:
SLF4J: Class path contains multiple SLF4J providers.
SLF4J: Found provider [org.slf4j.impl.JBossSlf4jServiceProvider@696da30b]
SLF4J: Found provider [ch.qos.logback.classic.spi.LogbackServiceProvider@4e7912d8]
SLF4J: See https://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual provider is of type [org.slf4j.impl.JBossSlf4jServiceProvider@696da30b]
I don't see currently a way to do this with preLaunchTask.
Just as a quick fix for this particular issue regarding slf4j (so not a global fix for the surefire exclusion option), the config can be set to select a specific provider:
"java.test.config": [
{
"workingDirectory": "${workspaceFolder}",
"vmArgs": [
"-Dslf4j.provider=ch.qos.logback.classic.spi.LogbackServiceProvider"// Replace with the appropriate provider classpath
]
}
]
In case people stumble on this issue like I did, might save some time :)
Activity
ansyral commentedon Mar 2, 2018
parkertomatoes it is "mvn test" that executes the maven plugin to remove logback from the test classpath. If I understand it correctly, you want to the ability to configure some preprocess action before runner running the tests? Currently we don't support this.
IzakMarais commentedon Mar 9, 2018
I also have some similar problems. We use protocolbuffer definitions that generate java source files that are included in the tests. They are not picked up when using this plugin.
Source files are generated like so in the pom:
we event try to add it to the test class path like so (this is not needed for
mvn testto work).ansyral commentedon Mar 22, 2018
parkertomatoes Izak Marais (@IzakMarais) we'll support test configuration this release, where you can configure
prelanchTaskto execute maven goals, what do you think about this?ansyral commentedon Apr 3, 2018
parkertomatoes Izak Marais (@IzakMarais) we've supported test configuration this release and you can configure the
preLaunchTaskto add maven goal scriptdannormond commentedon Apr 11, 2018
I'm not sure the preLaunchTask is what is wanted for this. I've put in a preLaunchTask to call 'mvn test' but that just runs all my tests through maven before attempting to run one test through Code.
ansyral commentedon Apr 13, 2018
Dann Ormond (@dannormond) does your pom.xml contain customized goal execution in or before "test" phase? If so, you could add script like
mvn groupID:artifactID:version:goalin the preLaunchTask to achieve the same effect with maven test.goldmann commentedon Aug 4, 2023
Can we consider reopening this? What do we see here is the same as in #1436, but for Maven.
The original request was about being able to exclude some depednencies from the test classpath. In case of Maven it is done like this:
Running tests via Maven CLI works perfectly fine, but when executed in vscode, these fail with messages similar to this:
I don't see currently a way to do this with
preLaunchTask.clement-socgen commentedon Feb 17, 2026
Just as a quick fix for this particular issue regarding slf4j (so not a global fix for the surefire exclusion option), the config can be set to select a specific provider:
In case people stumble on this issue like I did, might save some time :)