如何在 maven 中安装 test-jar? [英] How do I install a test-jar in maven?

查看:87
本文介绍了如何在 maven 中安装 test-jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我想安装的 test-jar.我不确定是否有不同的方式来安装 test-jar,例如定义一个属性来告诉 maven 它是一个 test-jar.

I have a test-jar which I would like to install. I am not sure if there is a different way to install test-jars, such as defining a property that tells maven it is a test-jar.

此外,groupId 和 artifactId 与用于测试的另一个 jar 相同.

Also, the groupId and artifactId are the same as another jar for which the test is made from.

到目前为止,这是我的安装命令的样子:

So far this is how my install command looks like:

mvn install:install-file -DgroupId=com.example -DartifactId=example -Dpackaging=jar -Dversion=1.2.3 -Dfile=example-test.jar -DgeneratePom=true

那么我究竟要如何安装一个测试 jar 呢?我知道必须告诉 Maven 它是一个测试 jar,因为 groupId 和 artifactId 与另一个 jar 相同(这将是 example-test.jar 测试的 jar).

So how exactly would I install a test jar? I know there has to be something to tell maven it is a test-jar since the groupId and artifactId is the same as another jar(which would be the jar that example-test.jar is a test of).

推荐答案

您无需手动安装它们.Maven 会在执行时为你做这些:

You don't need to install them manually. Maven will do this for you when executing:

mvn clean install

您需要按照以下方式进行配置:

You need a configuration along the lines of:

    ...
    <build>
       <plugins>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-jar-plugin</artifactId>
               <version>2.2</version>

               <executions>
                   <execution>
                       <goals>
                           <goal>test-jar</goal>
                       </goals>
                   </execution>
               </executions>
           </plugin>
        </plugins>
    </build>
    ...

然后,稍后在您需要使用它的其他模块中,您需要将依赖项的类型定义为:

Then, later on in your other module where you'll need to use it, you need to define the dependency's type as:

 <dependency>
    <groupId>com.foo</groupId>
    <artifactId>bar</artifactId>
    <version>1.2.3</version>
    <type>test-jar</type>
    <scope>test</scope>
 </dependency>

这篇关于如何在 maven 中安装 test-jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆