How to include unit test artifacts in a simple Java application?

Asked

Viewed 22 times

0

This is my project in my repository;

PROJECT

Note the pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test.wladimir</groupId>
    <artifactId>GamerGourmet</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>1.7.22</version>
                <executions>
                    <execution>
                        <id>l4j-gui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>gui</headerType>
                            <outfile>target/GamerGourmet.exe</outfile>
                            <jar>target/${project.artifactId}-${project.version}.jar</jar>

                            <dontWrapJar>false</dontWrapJar>
                            <errTitle>Error in launch4j plugin</errTitle>
                            <classPath>
                                <mainClass>com.test.wladimir.gamergourmet.main.GamerGourmet</mainClass>
                            </classPath>
                            <jre>
                                <minVersion>1.8.0</minVersion>
                                <initialHeapSize>512</initialHeapSize>
                                <maxHeapSize>1024</maxHeapSize>
                            </jre>
                            <versionInfo>
                                <fileVersion>0.0.0.1</fileVersion>
                                <txtFileVersion>0.0.0.1</txtFileVersion>
                                <fileDescription>des</fileDescription>
                                <copyright>Copyright (c) 2018 </copyright>
                                <companyName>comp</companyName>
                                <productVersion>0.0.0.1</productVersion>
                                <txtProductVersion>${project.version}</txtProductVersion>
                                <productName>GamerGourmet</productName>
                                <internalName>GamerGourmet</internalName>
                                <originalFilename>GamerGourmet.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <name>GamerGourmet</name>
</project>

How do I include the Junit package in this pom.xml file?

This is Junit’s package;

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

I’m using the Netbeans

1 answer

3

You need to add the tag dependencies in your pom, after or before the tag build:

[...]
</build>
<name>GamerGourmet</name>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>

This tag is responsible for managing your project’s dependencies. For each new dependency, just add it inside the tag dependencies.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.