首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Maven程序集:添加同一工件的不同版本

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

Stack Overflow用户
提问于 2010-11-30 18:17:42
回答 4查看 19.3K关注 0票数 18

我使用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>

对于源代码,依赖解析器删除旧版本,归档中仅打包1.1.0

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

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

有什么想法吗?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-11-30 22:11:14

我找到了一个解决方案,使用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>

现在,我只需要在我的汇编xml中添加以下几行

    <fileSet>
        <directory>${project.build.directory}/lib</directory>
        <outputDirectory>/lib</outputDirectory>
        <filtered>false</filtered>
        <includes>
            <include>*.jar</include>
        </includes>
        <fileMode>0600</fileMode>
    </fileSet>
票数 13
EN

Stack Overflow用户

发布于 2010-11-30 18:25:24

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

总的来说,Maven试图鼓励好的应用程序设计,并故意让它认为是坏主意的事情变得困难。

票数 12
EN

Stack Overflow用户

发布于 2010-11-30 20:58:38

另一个丑陋的解决方案可能是使用WAR文件覆盖,利用此机制在应用覆盖时不关注组件JAR文件的版本这一事实。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4312553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档