Unable to suppress excessive logs from scalatest-maven-plugin

376 Views Asked by At

Background

I am facing excessive logging from default Logger when I run scala tests from maven because it is not picking up the logback.xml on the classpath with the correct logging definitions

So my maven config is fairly generic (as per scalatest-maven-plugin docs) Looks like this

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <!-- enable scalatest -->
        <plugin>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <version>1.0</version>
            <configuration>
                <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                <junitxml>.</junitxml>
                <filereports>MyProj_TestSuite.txt</filereports>
                <forkMode>never</forkMode>
            </configuration>
            <executions>
                <execution>
                    <id>test</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

I have a logback.xml in my src/main/resources which gets copied over to target/classes

Things I tried so far

Have spent a whole day to figure out why this is not being picked up -- using the following configuration optional entries

<runpath>
${project.basedir}/target/classes
</runpath>

<systemProperties>
<logback.configurationFile> ${project.basedir}/src/main/resources/logback.xml</logback.configurationFile>
</systemProperties>

<argLine>
-Dlogback.configurationFile=src/main/resources/logback.xml
</argLine>

If I run it like this (from command line) from ${project.basedir}

mvn test -Dlogback.configurationFile=./src/test/resources/logback.xml

it works

I have looked at similar issues on stack and even tried adding this

    <build>
        <testResources>
            <testResource>
                <directory>${project.basedir}/target/classes</directory>
            </testResource>
            <testResource>
                <directory>${project.basedir}/src/test/resources</directory>
            </testResource>
        </testResources>
 </build>

This did not work - I think it is because I am using scala-maven-test plugin which has its own configuration block.

Any help on how to do this from inside the pom.xml will be much appreciated.

1

There are 1 best solutions below

0
On

Try to have /src/test/resources/logback-test.xml logback configuration file. It works for me with scalatest-maven-plugin of 2.0.2 version.