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 2022-12-05 23:35  荣锋亮  阅读(606)  评论(0编辑  收藏  举报

导航