Maven 项目依赖于同一工件的两个版本 [英] Maven project depending on two versions of the same artifact

查看:20
本文介绍了Maven 项目依赖于同一工件的两个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目有两个单独的模块,使用 sqlline 和另一个依赖于 jline 的库(比如 OtherLib).但是在不同的版本上.

I have a project with two seperate modules that uses sqlline and another library(say OtherLib) that depends on jline. However on different versions.

Module1 使用 Sqlline 取决于 jline 2.10
Module2 使用 OtherLib 依赖于 jline 0.9.94

Module1 uses Sqlline depends on jline 2.10
Module2 uses OtherLib depends on jline 0.9.94

而且这两个版本不兼容.因此,我设置了类路径,以便 Module1 首先在 $HOME/lib/module1 文件夹中搜索,然后在 $HOME/lib 文件夹中搜索 Module2.

And the two versions are incompatible. Therefore I have set the classpaths such that Module1 will search in $HOME/lib/module1 folder first and Module2 in $HOME/lib folder first.

有没有一种方法可以指定 maven 首先将工件下载到源目录(比如 ../resources/lib),然后在 assembly 中的打包时间将其复制到包中.xml?

Is there a way to specify maven to download the artifact to a source directory first(say ../resources/lib) and then copy it to package during packaging time in assembly.xml?

我知道可以使用以下代码从源目录复制.

I know that for copying from source directory the following code can be used.

<fileSets>
   <fileSet> 
        <directory>../resources/lib</directory>
        <outputDirectory>${HOME}/lib/module1</outputDirectory>
        <directoryMode>755</directoryMode>
        <fileMode>644</fileMode>
        <includes>
            <include>*.jar</include>
        </includes>
    </fileSet>
</fileSets>

还要让 maven 下载我可以使用的依赖项(用于 Module2)

Also to get maven to download the dependency I can use (for Module2)

 <dependencySets>
    <dependencySet>
        <useProjectArtifact>false</useProjectArtifact>
        <outputDirectory>${HOME}/lib</outputDirectory>
        <directoryMode>755</directoryMode>
        <fileMode>644</fileMode>
        <includes>
            <include>jline:jline:jar:0.9.94</include>
        </includes>
    </dependencySet>
<dependencySets>

如何确保先将 jline:jline:jar:2.10 下载到 ../resources/lib 文件夹?

How can I make sure jline:jline:jar:2.10 is downloaded to ../resources/lib folder first?

推荐答案

我使用 此处找到了一个答案>maven-dependency-plugin

I found a an answer here using maven-dependency-plugin

pom.xml

<build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <version>2.1</version>
         <executions>
           <execution>
               <id>copy-model</id>
               <phase>package</phase>
               <goals>
                  <goal>copy</goal>
               </goals>
               <configuration>
                 <artifactItems>
                   <artifactItem>
                       <groupId>jline</groupId>
                       <artifactId>jline</artifactId>
                       <version>2.10</version>
                       <type>jar</type>
                   </artifactItem>
                 <artifactItems>
                 <outputDirectory>../../resources/lib</outputDirectory>
               </configuration>
           </execution>
        </executions>
     </plugin>
   <plugins>  
 <build>
   

assembly.xml

   <fileSet>
        <directory>../../resources/lib</directory>
        <outputDirectory>${HOME}/lib/module1</outputDirectory>
        <directoryMode>755</directoryMode>
        <fileMode>644</fileMode>
        <includes>
            <include>jline-*</include>
        </includes>
    </fileSet>

jline-0.9.94 与任何其他依赖项一样包含在 dependencySet 中.我希望这有帮助.:)

jline-0.9.94 is included in a dependencySet as any other dependency. I hope this helps. :)

这篇关于Maven 项目依赖于同一工件的两个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆