2017-06-14 26 views
0

我已经成功地使用mvn -U dependency:copy-dependencies下载了所有的依赖项 - 比如说module-a.jar,module-b.jar和module-c.jar。使用maven将依赖关系压缩到文件树中

而不是让他们在一个平面的目录中,我需要在特定的层次结构中的罐子,也压缩。

release.zip 
| 
- base/classes/ 
|   | 
|   - module-a.jar 
| 
- customer/ 
     | 
     - classes/ 
     | | 
     |  - module-b.jar 
     | 
     | 
     - plugins/ 
      | 
      - module-c.jar  

有4个项目,上述3个模块加上聚集在某一版本的所有模块项目。

是否有可能告诉maven或maven-dependency-plugin将依赖关系复制到所需的结构中?怎么样?

+0

什么是您的特殊布局的逻辑? (如何决定把每个地方放在哪里?) –

+0

如果我可以解决这个问题的固定映射,我会很高兴。真正的项目包括30多个罐子。除此之外,在某些情况下,具有相同groupId的元素必须被复制到同一个文件夹中,但这不是一个规则,并且还需要将模块x及其所有依赖项都复制到同一个文件夹中文件夹为x。 – mike

+2

它必须是依赖插件吗?您可以使用插件将每个jar复制到正确的目录,然后使用另一个插件将整个树打包为zip。 https://maven.apache.org/plugins/maven-assembly-plugin/更好 - 它允许创建自定义装配描述符。 – vempo

回答

0

我用自定义组装描述符的maven程序集插件。在那个描述符中,我不得不使用一个模块集。在那里,我可以管理所有不同的目的地目录(和他们的内容)为dependencySet s。

我不得不建立一个新项目,其中包含我想打包为依赖项的所有罐子。在同一个项目中,我不得不参考装配描述符来配置maven装配插件。

<assembly 
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 
    <id>install</id> 
    <includeBaseDirectory>false</includeBaseDirectory> 

    <formats> 
     <format>zip</format> 
    </formats> 

    <moduleSets> 
     <moduleSet> 

      <!-- Needed to have access to all projects in multi module build --> 
      <useAllReactorProjects>true</useAllReactorProjects> 

      <!-- If there is no include, every dependency (or at least more) are included --> 
      <includes> 
       <include>com.company:artifact_01</include> 
      </includes> 

      <binaries> 
       <unpack>false</unpack> 
       <outputDirectory>main/dir</outputDirectory> 

       <dependencySets> 

        <dependencySet> 
         <includes> 
          <include>com.company:artifact_02</include> 
          <include>com.company:artifact_03</include> 
         </includes> 
         <outputDirectory>/main/dir</outputDirectory> 
        </dependencySet> 

        <dependencySet> 
         <includes> 
          <include>org.apache.felix:org.apache.felix.framework</include> 
         </includes> 
         <outputDirectory>/dir/felix</outputDirectory> 
        </dependencySet> 

        <dependencySet> 
         <includes> 
          <include>com.company:artifact_04</include> 
         </includes> 
         <outputDirectory>/dir/felix/plugin</outputDirectory> 
        </dependencySet> 
      </binaries> 
     </moduleSet> 
    </moduleSets> 

</assembly>