背景
当我从 maven 运行 scala 测试时,我正面临来自默认 Logger 的过多日志记录,因为它没有使用正确的日志记录定义在类路径上拾取 logback.xml
所以我的 maven 配置相当通用(根据 scalatest-maven-plugin 文档)看起来像这样
<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>
我的 src/main/resources 中有一个 logback.xml,它被复制到 target/classes
到目前为止我尝试过的事情
花了一整天的时间来弄清楚为什么没有被选中 - 使用以下配置可选条目
<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>
如果我从 ${project.basedir} 像这样(从命令行)运行它
mvn test -Dlogback.configurationFile=./src/test/resources/logback.xml
有用
我在堆栈上查看了类似的问题,甚至尝试添加这个
<build>
<testResources>
<testResource>
<directory>${project.basedir}/target/classes</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
这不起作用 - 我认为这是因为我使用的是 scala-maven-test 插件,它有自己的配置块。
任何有关如何从 pom.xml 内部执行此操作的帮助将不胜感激。