maven assembly 依赖的管理和过滤

最近在做项目的时候,在我的assembly中,除了要把项目依赖的jar打到服务器端zip的lib目录之中,还需要在服务器的application folder 放置一个client_example的目录,这client_example, 需要将client依赖的jar打包到client_example下的lib目录。两个lib目录有重叠。起初的assembly的POM的dependencies设置如下,

 

<dependencies>
    <dependency>
   <groupId>com.my.test</groupId>
   <artifactId>server_app</artifactId>
   <version>1.0</version>
   <type>jar</type>
  </dependency>
  <dependency>
   <groupId>com.my.test</groupId>
   <artifactId>client_app</artifactId>
   <version>1.0</version>
   <type>jar</type>
  </dependency>

<dependencies>

server和client app 都依赖log4j-1.2.17.jar

我要的输出包希望包含下面的

<program folder>

            -bin

            -conf

            -lib

           -client example

                 -bin

                 -lib

 

assembly的descriptor中的dependencySets如下:

<dependencySets>
  <dependencySet>
   <outputDirectory>${project.parent.name}/lib</outputDirectory>
   <useTransitiveFiltering>true</useTransitiveFiltering>
   <includes>
       <include>
            com.my.test:server_app

         </include> 
   </includes>

  </dependencySet>
  <dependencySet>
   <outputDirectory>${project.parent.name}/client_example/lib</outputDirectory>
   <useTransitiveFiltering>true</useTransitiveFiltering>
   <includes>
    <include>
     com.my.test:client_app

    </include>  
    <include>
     log4j:log4j:jar
    </include> 
     </includes> 
   <excludes>
   </dependencySet>

刚开始,在我的第二个dependencySet下没有include log4j, 结果client/lib下没有log4j.

 

经过我用mvn dependency:tree 查看,发现在pom的依赖管理,如果一个jar在第一个依赖jar的传递依赖中的话,他就不会在出现在后面jar的传递依赖中,在descriptor中显式指定,才会包含所需的依赖。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值