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

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

问题描述

我有一个我想安装的测试罐。我不确定是否有不同的方法来安装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

那么我将如何安装测试罐?我知道有必要告诉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中安装测试罐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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