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

查看:117
本文介绍了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

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天全站免登陆