Surefire(Maven)是否能够运行多个不同版本的依赖项?如果是,如何运行?

aydmsdu9  于 12个月前  发布在  Maven
关注(0)|答案(1)|浏览(175)

我想知道是否有可能让Maven Surefire插件在不同版本的依赖项下运行多次(多次执行)?
这可能很方便,例如确保您的代码仍然与项目依赖项的先前版本兼容。
我至少运行了两次surefire的执行:

<plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
        <executions>
          <execution>
            <id>test-default-deps</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <skip>false</skip>
            </configuration>
          </execution>
          <execution>
            <id>test-anotherversion-deps</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <skip>false</skip>
              <reportsDirectory>${project.build.directory}/surefire-reports-anotherversion-deps</reportsDirectory>
              <dependencies>

                <!-- Version different of the default for the project -->
                <dependency>
                  <groupId>com.dep.groupid</groupId>
                  <artifactId>dep-artifact</artifactId>
                  <version>anotherversion</version>
                </dependency>

              </dependencies>
            </configuration>
          </execution>
        </executions>
      </plugin>

字符串
但是这个不同的版本在第二次执行时没有被考虑在内。我是在尝试做一些不可行的事情还是我做错了?有没有其他插件可以帮助实现这个目的?

hc2pp10m

hc2pp10m1#

现在这是可能的,因为它支持additionalClasspathDependenciesclasspathDependencyExclude,允许修改测试类路径。这里是一个例子:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.2</version>
    <executions>
       <execution>
          <id>2.0</id>
           <goals>
              <goal>test</goal>
           </goals>
           <phase>test</phase>
           <configuration>
              <reportNameSuffix>2.0</reportNameSuffix>
              <classpathDependencyExcludes>
                 <classpathDependencyExclude>groupId:artifactId</classpathDependencyExclude>
                 <!-- Add any transitives here -->
              </classpathDependencyExcludes>
              <additionalClasspathDependencies>
                 <additionalClasspathDependency>
                    <groupId>groupId</groupId>
                    <artifactId>artifactId</artifactId>
                    <version>2.0</version>
                 </additionalClasspathDependency>
              </additionalClasspathDependencies>
           </configuration>
        </execution>
        <execution>
           <id>3.0</id>
           <goals>
              <goal>test</goal>
           </goals>
           <phase>test</phase>
           <configuration>
              <reportNameSuffix>3.0</reportNameSuffix>
              <classpathDependencyExcludes>
                 <classpathDependencyExclude>groupId:artifactId</classpathDependencyExclude>
                 <!-- Add any transitives here -->
              </classpathDependencyExcludes>
              <additionalClasspathDependencies>
                 <additionalClasspathDependency>
                    <groupId>groupId</groupId>
                    <artifactId>artifactId</artifactId>
                    <version>3.0</version>
                 </additionalClasspathDependency>
              </additionalClasspathDependencies>
           </configuration>
        </execution>
     </executions>
  </plugin>

字符串

相关问题