如何在maven-assembly-plugin中包含junit测试?

huangapple go评论74阅读模式
英文:

How to include junit tests in maven-assembly-plugin?

问题

我有一个使用 maven-assembly-plugin 构建最终 JAR 文件的旧应用程序。

问题:mvn package 跳过了所有的 junit 测试(到目前为止还没有任何测试)。

问题:我如何强制汇总插件在构建最终 JAR 文件之前先执行测试?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>package_path.foo</mainClass>
            </manifest>
        </archive>
        <descriptors>
            <descriptor>src/main/assembly/test-jar-with-dependencies.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
英文:

I have a legacy app that builds the final jar using maven-assembly-plugin.

Problem: mvn package skips all junit tests (there have not been any so far).

Question: how can I force the assembly plugin to execute tests first before building the final jar?

&lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
        &lt;archive&gt;
            &lt;manifest&gt;
                &lt;mainClass&gt;package_path.foo&lt;/mainClass&gt;
            &lt;/manifest&gt;
        &lt;/archive&gt;
        &lt;descriptors&gt;
            &lt;descriptor&gt;src/main/assembly/test-jar-with-dependencies.xml&lt;/descriptor&gt;
        &lt;/descriptors&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;phase&gt;package&lt;/phase&gt;
            &lt;goals&gt;
                &lt;goal&gt;single&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;

答案1

得分: 1

maven-surefire-plugin 丢失了。从 spring-boot 来的,我不知道必须显式添加此插件来执行 @Test 类。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.1.2</version>
</plugin>
英文:

It turned out that the maven-surefire-plugin was missing. Comming from spring-boot, I was not aware this plugin has to be added explicit for executing @Test classes.

  &lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
    &lt;version&gt;3.1.2&lt;/version&gt;
  &lt;/plugin&gt;

huangapple
  • 本文由 发表于 2023年6月26日 22:43:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定