[英]maven assembly plugin: control over directories
I'm trying to convert some groovy (gradle) code to maven. 我正在尝试将一些常规(渐变)代码转换为Maven。 Where possible, we're trying to use off-the-shelf plugins rather than custom ones.
在可能的情况下,我们尝试使用现成的插件,而不是自定义的插件。
We wanted to use the maven assembly plugin to assemble a tar file that we'll use for deployment. 我们想使用maven程序集插件来组装要用于部署的tar文件。 The directory structure is important for our deployment tools, and I seem to be fighting against getting maven to get it to do what I want.
目录结构对于我们的部署工具很重要,而且我似乎在与让maven使其执行我想要的工作作斗争。
The key problem on the bottom code snippet is the fact that the jar ended up in a target
directory in the tar file. 底部代码段中的关键问题是jar最终位于tar文件的
target
目录中。 My question is: can this be avoided? 我的问题是:可以避免吗? or should I cut my losses and write a simple custom plugin to do this?
还是应该减少损失并编写一个简单的自定义插件来做到这一点?
(its possible I'm putting 2 and 2 together and getting 5, but it does seem related to this bug here ) (其可能我把2和2在一起并得到5,但它似乎与此相关的错误这里 )
Directory structure (After running the build) 目录结构(运行构建后)
.
└── project1
├── config
│ └── foo.config
├── pom.xml
├── src
│ └── main
│ ├── assembly
│ │ └── assembly.xml
│ └── java
│ └── com
│ └── foo
│ └── bar
│ └── App.java
└── target
├── archive-tmp
├── classes
│ └── App.class
├── maven-archiver
│ └── pom.properties
├── my-static-jar-name-bundle.tar
└── my-static-jar-name.jar
Assembly file 汇编文件
<assembly>
<id>bundle</id>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}</directory>
<outputDirectory>/spooge</outputDirectory>
<includes>
<include>**/*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/config</directory>
<outputDirectory>appconfig</outputDirectory>
<includes>
<include>**/*.config</include>
</includes>
</fileSet>
</fileSets>
</assembly>
contents of the tar file when the build has finished (note the jar is in a 'target' subfolder) 构建完成后tar文件的内容(请注意jar位于“目标”子文件夹中)
tar xvf project1/target/my-static-jar-name-bundle.tar
x spooge/target/my-static-jar-name.jar
x appconfig/foo.config
Try changing the fileset as shown: 尝试如下所示更改文件集:
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/spooge</outputDirectory>
<includes>
<include>**/*.jar</include>
</includes>
</fileSet>
The way it's currently configured, the assembly plugin is searching project1
s entire directory for any jar files. 程序集插件当前配置的方式是在
project1
的整个目录中搜索任何jar文件。 The only one it finds is in the target
directory, so Maven happily includes it in the tar. 它找到的唯一一个位于
target
目录中,因此Maven乐于将其包含在tar中。 The change I suggest uses project1/target
as the starting point, so I think you'll get the result you want. 我建议的更改以
project1/target
为起点,因此我认为您将获得所需的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.