Maven project depending on two versions of the same artifact

前端 未结 2 1360
谎友^
谎友^ 2020-12-03 17:49

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

External Librari

相关标签:
2条回答
  • 2020-12-03 18:30

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

    In 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>
       
    

    And in 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 is included in a dependencySet as any other dependency. I hope this helps. :)

    0 讨论(0)
  • 2020-12-03 18:42

    If you're absolutely sure, what you're doing, you can repackage one of the version using something like maven-shade-plugin. But please be absolutely sure, what you're doing.

    With maven-shade-plugin you could create a new Maven module, say jline:jline_2_10:jar:1.0 and use jline:jline:jar:2.10 as a dependency. The maven-shade-plugin would then package it in your jline_2_10-1.0.jar.

    Since your new artifact has its own groupId:artifactId combination, there will be no conflicts with the other jline:jline:jar:0.9.94 artifact, so you'll happily have both in the classpath.

    0 讨论(0)
提交回复
热议问题