简体   繁体   中英

Multimodules maven project: scalatest fails in root folder

I am trying to execute tests on a multimodule scala project:

Myproject 
    -module A
    -module B

Module A is a front end, B is a scala project with tests. When I go in Myproject/B and execute mvn scalatest:test (or mvn test), they are executed fine. However, if I try from the root folder, I got an error which prevents me from executing a mvn install unless I skip the tests (and that is bad).

The error is: Could not find or load main class org.scalatest.tools.Runner .

Apparently, scalatest is looking for non existant tests classes in the root folder, that really only have the main pom.xml, all sources are in the sub modules A and B

B also has submodules but the tests there are executed and discovered fine if I run maven commands directly under B directory. Really, the issue is when I am under the root directory. Compilation and even sbt-complier:testCompile run fine, it is really scalatest:test that fails almost immediately:

 [INFO] Myproject.......................................... FAILURE [ 1.108 s]
 [INFO] B................................................... SKIPPED
 [INFO] A................................................... SKIPPED
 [ERROR] Failed to execute goal org.scalatest:scalatest-maven-plugin:2.0.0:test (test) on project Myproject: There are test failures -> [Help 1]

Extract from the pom.xml in Myproject:

<project>
    <groupId>.....</groupId>
    <artifactId>;;;;;;</artifactId>
    <packaging>pom</packaging>
    <description>Myproject</description>
    <version>....</version>
    <name>Myproject</name>
    <modules>
        <module>A</module>
        <module>B</module>
    </modules>

     <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.12</artifactId>
            <version>${scalatest.version}</version>
            <scope>test</scope>
        </dependency>
         </dependencies>
    </dependencyManagement>
    <build>
           <plugins>
        <plugin>
            <groupId>com.google.code.sbt-compiler-maven-plugin</groupId>
            <artifactId>sbt-compiler-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <configuration>
                <skipTests>true</skipTests>
                <!-- I need to set that to true and override that in the pom.xml from the module B -->
            </configuration>
        </plugin>
    </plugins>
</build>


</project>

Thank you.

Ok, so I believe I found a solution. The mvn clean test works, so here is what I did: basically, in the root pom I said to ignore the configuration comming from the parent, same thing in the module A, then redifine everything in the module B. I had to tweak a bit what goal/id to use in scalatest, but using "mvn test" fro meither the root directory or the B module directory works.

Surefire test skiped in the parent pom.

Myproject and A pom.xml, under build/plugins:

    <plugin>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>test</id>
                    <phase>none</phase>
                </execution>
            </executions>
        </plugin>

in B pom.xml under build/plugins:

<plugin>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>scala-test</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                <junitxml>.</junitxml>
                <skipTests>false</skipTests>
            </configuration>
        </plugin> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM