Maven程序集:添加相同工件的不同版本

Vla*_*rce 18 java maven-2 maven-plugin maven-assembly-plugin

我使用maven程序集插件创建我的应用程序存档.我的pom中存在的所有依赖都包含在内,没有任何问题.

现在我需要包含两个或更多版本的相同工件.

如果在我的pom我放

<dependencies>
        [...]
        <dependency>
            <groupId>db.test</groupId>
            <artifactId>my-model</artifactId>
            <version>1.0.3</version>
        </dependency>
        <dependency>
            <groupId>db.test</groupId>
            <artifactId>my-model</artifactId>
            <version>1.1.0</version>
        </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

源代码依赖性解析器删除旧版本,只有1.1.0打包在存档中

我尝试使用程序集xml描述符文件包含jar.我没有找到任何解决方案.

一种可能的解决方案是手动将所有需要的model.jar放入文件夹中,并告诉程序集将其复制到存档中.但我正在寻找一个更可配置的解决方案.

任何的想法 ?

Vla*_*rce 13

我通过使用maven-dependency-plugin来复制已解决的pom依赖项和其他jar,找到了一个解决方案.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
    <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
            <goal>copy-dependencies</goal>
        </goals>
        <configuration>
            <outputDirectory>${project.build.directory}/lib</outputDirectory>
            <overWriteReleases>false</overWriteReleases>
            <overWriteSnapshots>false</overWriteSnapshots>
            <overWriteIfNewer>true</overWriteIfNewer>
            <includeScope>runtime</includeScope>
        </configuration>
    </execution>
    <execution>
        <id>copy-model</id>
        <phase>package</phase>
        <goals>
            <goal>copy</goal>
        </goals>
        <configuration>
            <artifactItems>
                <artifactItem>
                    <groupId>my.test.pkg</groupId>
                    <artifactId>my-model</artifactId>
                    <classifier>server</classifier>
                    <version>1.0.3</version>
                    <type>jar</type>
                </artifactItem>
                <artifactItem>
                    <groupId>my.test.pkg</groupId>
                    <artifactId>my-model</artifactId>
                    <classifier>server</classifier>
                    <version>1.1.0</version>
                    <type>jar</type>
                </artifactItem>
            </artifactItems>
            <outputDirectory>${project.build.directory}/lib</outputDirectory>
        </configuration>
    </execution>
</executions>
Run Code Online (Sandbox Code Playgroud)

现在我只需要在程序集xml中添加以下行

    <fileSet>
        <directory>${project.build.directory}/lib</directory>
        <outputDirectory>/lib</outputDirectory>
        <filtered>false</filtered>
        <includes>
            <include>*.jar</include>
        </includes>
        <fileMode>0600</fileMode>
    </fileSet>
Run Code Online (Sandbox Code Playgroud)


Pet*_*rey 12

Maven认为一次拥有多个版本的模块没有任何意义.它假定较新的版本替换旧版本.如果不是,那就不是同一个模块.我建议你给新模块一个不同的名称,并确保它有不同的包,以避免选择随机模块.

总的来说,Maven试图鼓励良好的应用程序设计,故意让它很难做出它已经确定为坏主意的事情.

  • 我们需要在我们的发行版中提供多个不同版本的数据库驱动程序,以便我们的应用程序可以支持数据库的不同旧版本和当前版本.它们都是相同的groupId:artifactId但版本不同.我们当然会将它们打包在.zip中的单独子目录中.但是maven不应该假设这么多,不考虑每个用例. (3认同)
  • 如果您打算同时使用两者,我会保证更改名称. (2认同)