maven-dependency-plugin unpack 使用

maven-dependency-plugin 是一个比较有用,但是大家日常使用不是很多的插件,

包含的功能

  • 解析依赖(显示依赖树,解析依赖的插件)
  • copy 依赖
  • 解压copy 依赖(unpack 比如需要部分jar 包中的内容,calcite 扩展开发经常使用到)

unpack 简单使用

比如我们需要依赖的jar的部分功能,但是不想依赖的太多,就可以基于此插件提供的能力解决

  • 参考pom.xml

我们提取webjars 中的内容,到自己的项目中,同时进行文件路径的改写(默认会与原始jar 的路径一致)
原始jar 目录

 

 

 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>org.example</groupId>
    <artifactId>maven-deps-apps</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>jquery</artifactId>
            <version>3.6.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <execution>
                        <id>unpack-parser-class</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.webjars.npm</groupId>
                                    <artifactId>jquery</artifactId>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                   // fileMappers 支持不少,比如,扁平以及正则处理,此处使用了FlattenFileMapper,注意此功能是3.1.2 开始的
                                    <fileMappers>
                                        <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FlattenFileMapper"/>
                                    </fileMappers>
                                    <outputDirectory>${project.build.directory}/classes/META-INF/resources/jquery/</outputDirectory>
                                    <includes>META-INF/resources/webjars/jquery/3.6.1/dist/**</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
  • 效果

 

 

dremio 参考使用

dremio 在利用calcite 进行sql 扩展的时候就使用了此功能

  • 参考配置

 

 

参考资料

https://sourcegraph.com/github.com/apache/maven-dependency-plugin@master/-/blob/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/UnpackDependenciesMojo.java?L81
https://maven.apache.org/plugins/maven-dependency-plugin/index.html
https://github.com/apache/maven-dependency-plugin

posted on   荣锋亮  阅读(710)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-12-05 nginx 动态模块问题
2021-12-05 基于minio s3 gateway 改造业务系统支持基于webhook的文件处理
2021-12-05 nginx 作为s3 的gateway
2020-12-05 golang 死锁&&静态检查的一些工具
2020-12-05 spring cloud 应用集成prometheus 监控实现服务发现的一些方法
2019-12-05 使用jdk 容器镜像注意默认编码问题
2018-12-05 lapis 项目添加prometheus 监控

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示