在测试包中生成测试jar和jar文件

22 maven maven-surefire-plugin

我想将我的测试包打包到jar文件中.如何从maven插件Surefire执行生成test-jar.

khm*_*ise 36

通过使用以下配置,您可以从测试中创建一个jar:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <executions>
      <execution>
        <goals>
          <goal>test-jar</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

要使用这种工件:

  <dependencies>
    <dependency>
      <groupId>groupId</groupId>
      <artifactId>artifactId</artifactId>
      <type>test-jar</type>
      <version>version</version>
      <classifier>tests</classifier>
      <scope>test</scope>
    </dependency>
  </dependencies>
Run Code Online (Sandbox Code Playgroud)

  • +1也提供用法 (5认同)

Dha*_*ana 18

您可以在pom中添加以下条目:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <goals>
                <goal>test-jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)