简体   繁体   中英

Maven: Usage of external libraries for integration test

Currently, I set up an integration test suite. The base is a Maven project with several modules which are dependent to each other to setup a database, to put some data into it and to run tests on it, before wrapping everything up. Additionally, I have modules with some utilities and test data in there.

The first step (not mentioned above) is the copy of a zipped image which includes a lot of JAR files which make up the software suite to be tested. Unfortunately, the software is not build by Maven, but by Ant, so I can not find the stuff in an Artifactory or something similar.

My problem is now, that I copy and unzip the image with an integration test method, but I do not know, how I can add the JAR files to the Maven classpath. All other modules need to compile and run against the jars extracted from the ZIP file.

How can I add the JARs to the Maven class path for later compiling and test runs? The destination of the ZIP content is always the same directory. Unfortunately, the names of the JARs contain version information (build numbers) which change. So an easy usage of system and the tag is not working so easily. A path entry like ${package.path}/lib/* / .jar would be great. Is there a plugin, maybe?

Or does anyone have a better idea to setup an integration test against prebuild JARs?

Create a single jar from all of your dependencies, everything in ${package.path}/lib/*/.jar .

You could use an ant task to create this jar, either before you run maven, or as part of your maven build.

To merge your jars, you can use the Ant Jar Task (see section Merging Archives). From there:

<jar destfile="build/main/checksites.jar">
    <fileset dir="build/main/classes"/>
    <restrict>
     <name name="**/*.class"/>
     <archives>
       <zips>
         <fileset dir="lib/main" includes="**/*.jar"/>
       </zips>
     </archives>
    </restrict>
</jar>

This creates a jar file which embeds all the classes from all the jars in lib/main.

You can then use the system scope which points at this jar as normal in maven. Note: if you create the jar in maven (via ant), then you should create the jar in target, so that it gets cleaned correctly.

To use an ant build file from maven, you can use the maven antrun plugin , similarly to:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>

    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <property name="local.project.artifact.name" value="${project.build.finalName}" />
                    <property name="local.distribution.artifact.name" value="${local.project.artifact.name}-distribution" />
                    <property name="local.distribution.artifact.file" value="${project.build.directory}/${local.distribution.artifact.name}.zip" />
                    <ant antfile="build-deploy.xml" />
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

This runs the ant build file build-deploy.xml in the package phase. The modifications necessary for your system are left as an exercise for the reader :-).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM