Maven程序集插件:包含文件而不占用其路径文件夹 [英] Maven assembly plugin: include file without taking its path folders
问题描述
我正在使用maven-assembly-plugin将依赖项ZIP文件(也由程序集插件生成)中的文件包含到最终发行的ZIP文件中.
I'm using maven-assembly-plugin to include files from a dependency ZIP (also generated with assembly plugin) into a final release ZIP file.
问题是我想从依赖项中选择要获取的文件,但不复制这些文件所在的文件夹路径.只是文件.
The issue is that I want to select which files from the dependency to get, but not copying the folder path where those files are. Just the files.
例如:
<assembly>
<formats>
<format>zip</format>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>package:artifactId:zip:*</include>
</includes>
<outputDirectory>sql/update/01.00.00_to_01.01.00</outputDirectory>
<unpack>true</unpack>
<unpackOptions>
<includes>
<include>oracle/update/1_alter_schema.sql</include>
<include>oracle/update/2_insert_data.sql</include>
</includes>
</unpackOptions>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>false</useTransitiveDependencies>
</dependencySet>
</dependencySet>
</assembly>
这将复制所需的文件,如下所示:
This copies the required files like this:
- sql/update/01.00.00_to_01.01.00/ oracle/update /1_alter_schema.sql
- sql/update/01.00.00_to_01.01.00/ oracle/update /2_insert_data.sql
- sql/update/01.00.00_to_01.01.00/oracle/update/1_alter_schema.sql
- sql/update/01.00.00_to_01.01.00/oracle/update/2_insert_data.sql
我只想复制没有原始 oracle/update/文件夹的文件,从而得到以下文件夹结构:
I would like to copy just the files without the original oracle/update/ folder, resulting in this folder structure:
- sql/update/01.00.00_to_01.01.00/1_alter_schema.sql
- sql/update/01.00.00_to_01.01.00/2_insert_data.sql
依赖项ZIP包含许多由不同项目使用的文件,因此在这里区分oracle和sql-server文件的结构是有意义的,但是对于这种分发,我不需要那些文件夹,而仅是文件.
The dependency ZIP contains many files used by different projects, therefore the structure to differentiate oracle from sql-server files makes sense there, but for this distribution I don't need those folders, just the files.
有人知道使用maven-assembly-plugin是否可能?
Does somebody knows if this is possible with maven-assembly-plugin?
非常感谢!
推荐答案
它应该通过拆分依赖项解压缩和文件汇编来工作.
It should work by splitting the dependency unzipping and the file assembly.
在执行组装工作之前,配置 dependency-plugin 以解压缩所需的依赖项:
Configure the dependency-plugin to unpack the desired dependency before performing the assembly work:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<includeArtifactIds>project-sql</includeArtifactIds>
<outputDirectory>${project.build.directory}/extract</outputDirectory>
<includes>oracle/update/1_alter_schema.sql,oracle/update/2_insert_data.sql</includes>
</configuration>
<executions>
<execution>
<id>unpack-sql</id>
<phase>prepare-package</phase>
<goals><goal>unpack-dependencies</goal></goals>
</execution>
</executions>
</plugin>
然后,在您的 assembly-distribution.xml 中,仅从子目录进行组装:
Then, in your assembly-distribution.xml, just assemble from the sub-directory:
<?xml version="1.0" encoding="UTF-8"?>
<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>distribution-${project.version}</id>
<formats>
<format>zip</format>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/extract/oracle/update</directory>
<outputDirectory>sql/update/01.00.00_to_01.01.00</outputDirectory>
</fileSet>
</fileSets>
</assembly>
这篇关于Maven程序集插件:包含文件而不占用其路径文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!