Specifying jar file in maven build argument

We have a project using maven. We are trying to run our unit test cases in the maven assembly itself, and for this we need to add the DB2 java driver, depending on all subprojects.

Instead, we need a solution to specify the absolute path of the jar file as an argument to the mvn command line to use it in unit test.

This is due to the fact that the driver box is available in our folder with the application server, and we do not want to specify it in the dependencies of our projects.

Could not find a suitable solution to search for it, so the request for an expert solution is here.

Any workaround would be of great help.

Thanks in advance.

+3
source share
3 answers

The usual way would be to add a dependency on the database driver and limit the dependency on testing (testing area). Thus, the library is available for unit tests, but will not be deployed and launched.

In practical terms, I would create a maven artifact for this driver (just a basic POM file) and put it on the maven build server (or a link if you use it for projects).

+1
source

We have a project using maven. We are trying to run our unit test cases in the maven assembly itself, and for this we need to add the DB2 java driver, depending on all subprojects.

Well, the maven path is to declare the DB2 driver as a scope dependency testin the parent project.

, jar mvn, unit test.

additionalClasspathElement , :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <additionalClasspathElements>
      <additionalClasspathElement>path/to/additional/resources</additionalClasspathElement>
    </additionalClasspathElements>
  </configuration>
</plugin>

, .

, , , . , , (, system). .

+1

, "system", , , - maven. jar lib :

<dependency>
    <groupId>groupId</groupId>
    <artifactId>artifactId</artifactId>
    <version>version</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/library.jar</systemPath>
</dependency>

groupId, artifactId , . . , , project.basedir. .

+1

Source: https://habr.com/ru/post/1753063/


All Articles