Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install a test-jar in maven?

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.

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 

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).

like image 570
Sujen Avatar asked Jun 24 '11 14:06

Sujen


People also ask

Does Maven include test classes in jar?

You can produce a jar which will include your test classes and resources. To reuse this artifact in an other project, you must declare this dependency with type test-jar : <project>

Where does Maven install jar?

You can find your installed JARs and dependencies in your local repository. By default, you can find it here: Windows: C:\Users\USERNAME\. m2\repository.

How do I run a jar test?

To show up the test results in Jenkins, running integration tests from executable jar needs to produce XML reports. If maven , gradle , ants are used to run tests, they by default or configuration generate XML reports. However, since we run tests from executable jar, we programmatically run tests using JUnitCore .


2 Answers

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> 
like image 54
carlspring Avatar answered Sep 30 '22 12:09

carlspring


mvn install:install-file      -DgroupId=com.example      -DartifactId=example      -Dversion=1.2.3      -Dclassifier=tests      -Dpackaging=test-jar      -Dfile=example-1.2.3-tests.jar 
like image 20
Rajani Karuturi Avatar answered Sep 30 '22 10:09

Rajani Karuturi