博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Apache Maven Dependency Plugin使用记录
阅读量:6480 次
发布时间:2019-06-23

本文共 4350 字,大约阅读时间需要 14 分钟。

hot3.png

        在Maven工程中偶尔会遇到自主平台的项目相互依赖的情况,有时候我们希望在被依赖的项目jar包中使用的某些配置或少量页面等资源一同打包到jar文件里,在依赖项目中在解压到指定目录下来完成资源的转移,而不是手动的将被依赖项目中的配置或其他资源copy到新项目中使用,这样太麻烦且不利于统一管理。

        查询了网上许多资料推荐后,决定使用Apache Maven Dependency Plugin来完成此项解压和copy的操作,同时搭配Apache Maven Resources Plugin来进行资源的打包,从而实现关键资源的自动打包与解压操作。

        Apache Maven Dependency Plugin中比较常用的功能有:

  • dependency:copy  用来拷贝某一个或多个特定文件到指定目录;

  • dependency:copy-dependencies  用来拷贝依赖的文件到指定目录;

  • dependency:unpack  与 copy 类似,但会解压文件;

  • dependency:unpack-dependencies  与 copy-dependencies 类似,但会解压文件;

        日常开发中,我常通过 dependency:unpack 功能搭配 Apache Maven Resources Plugin 提供的打包功能来进行特定资源的自动发布。此处也以 dependency:unpack 为主,进行主要配置介绍。

        dependency:unpack 中参数:

Name Type Since Description
artifact String 1.0 The artifact to unpack from commandLine. UseartifactItems within the pom-configuration.
User property is: artifact.
artifactItems List 1.0 Collection of ArtifactItems to work on. (ArtifactItem contains groupId, artifactId, version, type, classifier, outputDirectory, destFileName and overWrite.) See Usagefor details.
excludes String 2.0-alpha-5 A comma separated list of file patterns to exclude when unpacking the artifact. i.e. **\/*.xml,**\/*.properties NOTE: Excludes patterns override the includes. (component code = return isIncluded( name ) AND !isExcluded( name );)
User property is: mdep.unpack.excludes.
ignorePermissions boolean 2.7 ignore to set file permissions when unpacking a dependency
Default value is: false.
User property is: dependency.ignorePermissions.
includes String 2.0-alpha-5 A comma separated list of file patterns to include when unpacking the artifact. i.e. **\/*.xml,**\/*.properties NOTE: Excludes patterns override the includes. (component code = return isIncluded( name ) AND !isExcluded( name );)
User property is: mdep.unpack.includes.
localRepositoryDirectory File 2.2 Path to override default local repository during plugin's execution. To remove all downloaded artifacts as part of the build, set this value to a location under your project's target directory
markersDirectory File 1.0 Directory to store flag files after unpack
Default value is: ${project.build.directory}/dependency-maven-plugin-markers.
outputAbsoluteArtifactFilename boolean 2.0 Output absolute filename for resolved artifacts
Default value is: false.
User property is: outputAbsoluteArtifactFilename.
outputDirectory File 1.0 Default output location used for mojo, unless overridden in ArtifactItem.
Default value is: ${project.build.directory}/dependency.
User property is: outputDirectory.
overWriteIfNewer boolean 2.0 Overwrite if newer
Default value is: true.
User property is: mdep.overIfNewer.
overWriteReleases boolean 1.0 Overwrite release artifacts
Default value is: false.
User property is: mdep.overWriteReleases.
overWriteSnapshots boolean 1.0 Overwrite snapshot artifacts
Default value is: false.
User property is: mdep.overWriteSnapshots.
silent boolean 2.0 If the plugin should be silent.
Default value is: false.
User property is: silent.
skip boolean 2.7 Skip plugin execution completely.
Default value is: false.
User property is: mdep.skip.
useJvmChmod boolean 2.5.1

will use the jvm chmod, this is available for user and all level group level will be ignored

since 2.6 is on by default
Default value is: true.
User property is: dependency.useJvmChmod.

        其中常用参数有:

  • artifactItems:用来包含声明需要解压的文件元素;

  • artifactItem:声明需要解压的文件;

  • outputDirectory:定义解压后输出的文件夹;

  • includes:定义输出包含的规则;

  • excludes:定义输出排除的规则。

        官方提供了,实际使用时的简易配置如下:

   [...]   
     
       
         
org.apache.maven.plugins
         
maven-dependency-plugin
         
2.10
         
           
             
unpack
             
package
             
               
unpack
             
             
               
                 
                   
junit
                   
junit
                   
3.8.1
                 
               
               
**/*.jsp,**/*.html
               
${project.build.directory}/alternateLocation
             
           
         
       
     
   
   [...] 

        需要注意一下的是,在配置 plugin 时,如果将其定义在<pluginManagement></pluginManagement>标签中时,需要在外面重新引用下该 plugin ,否则将不会生效。原因与 <pluginManagement> 标签的功能有关,相关信息可查阅<pluginManagement> 标签的功能。

        除此以外,若 <pluginManagement> 中声明的 goal 与 <plugin> 标签引用中的 goal 不相同时,该插件会执行两次分别完成两个目标,执行时会合并两次的配置参数。

        dependency:unpack-dependencies 与 dependency:unpack 功能类似,用来解压所有依赖的文件,因此不需要指定 artifactItemsdependency:copy 和 dependency:copy-dependencies 功能参照 unpack 即可,只是少了解压的过程。

参考来源:

                 

转载于:https://my.oschina.net/u/1156626/blog/411755

你可能感兴趣的文章
Sublime Text 3 配置react语法校验
查看>>
10个Python技巧
查看>>
机器学习初体验
查看>>
让你的 highcharts支持maxPointWidth属性
查看>>
JavaScript引用类型——“RegExp类型”的注意要点
查看>>
Fescar 发布 0.3.1 版本, 支持 ZooKeeper 注册中心
查看>>
知其所以然之永不遗忘的算法
查看>>
Cygwin在Windows8上使用(备忘)
查看>>
Android动态加载技术 系列索引
查看>>
Ionic如何创建自定义展开标题组件
查看>>
Command './js-ant' failed to execute
查看>>
Spring Cloud配置服务器
查看>>
vue + axios---封装一个http请求
查看>>
全栈必备 Java 基础
查看>>
互联网金融核心优势之变:从渠道创新到场景化大数据 ...
查看>>
ACM团队招新赛题解
查看>>
「镁客早报」科创板研讨细则曝光;特斯拉上海超级工厂破土动工 ...
查看>>
全网Star最多(近20k)的Spring Boot开源教程 2019 年要继续更新了! ...
查看>>
知新温故,从知识图谱到图数据库
查看>>
仓储+调度,YOGO智能配送站能否改变外卖配送格局? ...
查看>>