0

我终于成功地让 Maven 使用程序集文件将一堆 jar 压缩在一起并将其安装到我的本地存储库中。那已经够难了……

现在我的目标是配置另一个 maven 项目,这样当我执行“mvn test”时,它会拉入那个 zip,解压它,然后从那个 zip 文件中的 jar 中运行测试。有谁知道如何做到这一点?

这是组装项目的 POM:

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.pason</groupId>
<artifactId>RigFocusOnDataHub</artifactId>
<name>RigFocusOnDataHub</name>
<version>12.2.0-SNAPSHOT</version>
<packaging>pom</packaging>

<dependencies>
    ...
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <descriptors>
                    <descriptor>RigFocusOnDH.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>zip</id>
                    <!-- this is used for inheritance merges -->
                    <phase>package</phase>
                    <!-- append to the packaging phase. -->
                    <goals>
                        <goal>single</goal>
                        <!-- goals == mojos -->
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是第二个项目的 POM。不幸的是,它没有下载 RigFocusOnDataHub 的 zip 文件,而是从本地 repo 中获取所有 RigFocusOnDataHub 依赖项的 jar。

<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.pason</groupId>
<artifactId>RigFocusDHSystemTest</artifactId>
<version>12.2.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>com.pason</groupId>
        <artifactId>MurphyRigFocus</artifactId>
        <version>2.0.0-SNAPSHOT</version>
        <type>test-jar</type>
    </dependency>
    <dependency>
        <groupId>com.pason</groupId>
        <artifactId>RigFocusOnDataHub</artifactId>
        <version>12.2.0-SNAPSHOT</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>process-test-classes</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.pason</groupId>
                                <artifactId>MurphyRigFocus</artifactId>
                                <version>2.0.0-SNAPSHOT</version>
                                <type>test-jar</type>
                                <outputDirectory>${project.build.directory}/tests/MurphyRigFocus</outputDirectory>
                            </artifactItem>
                            <artifactItem>
                                <groupId>com.pason</groupId>
                                <artifactId>RigFocusOnDataHub</artifactId>
                                <version>12.2.0-SNAPSHOT</version>
                                <type>zip</type>
                                <outputDirectory>${project.build.directory}/tests/MurphyRigFocus</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <testClassesDirectory>${project.build.directory}/tests/MurphyRigFocus</testClassesDirectory>
                <reportsDirectory>${project.build.directory}/surefire-reports/MurphyRigFocus</reportsDirectory>
                <includes>
                    <include>**/*IT.*</include>
                </includes>
                <argLine>-Djava.library.path=${basedir}/target/classes/</argLine>
                <forkMode>pertest</forkMode>
            </configuration>
        </plugin>
    </plugins>
</build>

4

1 回答 1

1

您需要:

  1. 从 zip 中提取 jars - 这很容易使用 maven-dependency-plugin
  2. 削减传递依赖关系,这样你的 jars 就不会在路径中结束两次 - 你可以在源代码中使用 maven-shade-plugin 或在测试项目本身中使用依赖项排除
  3. 将罐子添加到您的测试类路径中,有很多方法可以做到这一点,我会先尝试在surefire配置中使用其他参数
于 2012-05-21T17:23:44.983 回答