程序集总是执行带有依赖项的 jar
您好,我创建了一个程序集来压缩项目的图像,并将其连接到我的 pom 文件中的打包阶段,这里的问题是当我执行“cleancompilepackage”时,它正在创建我所需的 zip 文件以及文件 -jar-我不想创建 with-dependency.jar 。我怎样才能抑制生成这个jar文件
这里是我的pom
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<descriptors>
<descriptor>
src/main/assembly/cat_image_resources_assembly.xml
</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>cat_image_resources</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<!-- appendAssemblyId>false</appendAssemblyId>
<Change the name to standard name >
<finalName>renameImages</finalName-->
</configuration>
</execution>
</executions>
</plugin>
程序集文件cat_image_resources_ assembly.xml
<assembly>
<id>cat_image_resources</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<baseDirectory>${artifactId}</baseDirectory>
<fileSets>
<fileSet>
<directory>exportedImages</directory>
<outputDirectory/>
<fileMode>644</fileMode>
</fileSet>
</fileSets>
</assembly>
它正在生成以下文件
CATImageExport2-1.0-SNAPSHOT-cat_image_resources.zip(需要5mb), CATImageExport2-1.0-SNAPSHOT-jar-with-dependency.jar(58mb,这是我想排除生成的依赖项)
Hi i created a assembly to zip images of the project, and i hooked it to package phase in my pom file, the problem here is when i execute "clean compile package " it is creating my required zip file along with a file -jar-with-dependencies.jar which i dont want to create. how can i supress generating this jar file
here is my pom
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<descriptors>
<descriptor>
src/main/assembly/cat_image_resources_assembly.xml
</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>cat_image_resources</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<!-- appendAssemblyId>false</appendAssemblyId>
<Change the name to standard name >
<finalName>renameImages</finalName-->
</configuration>
</execution>
</executions>
</plugin>
assembly file cat_image_resources_assembly.xml
<assembly>
<id>cat_image_resources</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<baseDirectory>${artifactId}</baseDirectory>
<fileSets>
<fileSet>
<directory>exportedImages</directory>
<outputDirectory/>
<fileMode>644</fileMode>
</fileSet>
</fileSets>
</assembly>
it is generating following files
CATImageExport2-1.0-SNAPSHOT-cat_image_resources.zip (5mb which is required),
CATImageExport2-1.0-SNAPSHOT-jar-with-dependencies.jar(58mb this is with dependencies which i want to exclude generating)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用
jar-with-dependencies
预定义描述符。您提供的代码片段没有显示任何类似的内容,并且按预期工作(将其粘贴到测试 POM 中后):仔细检查您是否没有从父 POM 继承插件配置(例如使用
mvn help: effective-pom
),因为您提供的 XML 片段按预期工作。The
-jar-with-dependencies.jar
file is typically created if you use thejar-with-dependencies
pre-defined descriptor. The snippet you provided doesn't show anything like that and works as expected (after pasting it in a test POM):Double check that you're not inheriting a plugin configuration from a parent POM (for example with
mvn help:effective-pom
) because the XML snippet you provided works as expected.您确定是程序集插件创建了依赖项 jar 文件吗?
我这么说是因为看起来程序集插件完全按照您指定的方式执行操作。但是,如果没有看到更多项目的 pom.xml 文件,我不能排除该项目的 pom.xml 文件中没有其他插件,甚至没有可以为您创建依赖项 jar 文件的父 pom.xml 文件。
Are you sure that it's the assembly plug-in creating the dependencies jar file?
I say that because it looks like the assembly plug-in is doing exactly as you specified. However, without seeing more of project's pom.xml file, I cannot rule out that there's not another plug-in in pom.xml file for the project or even a parent pom.xml file that could be creating the dependencies jar file for you.
回复:“有没有一种方法可以覆盖父 pom 定义?我的意思是是否可以忽略父 pom 定义并拥有自己的描述符,以便 jar-with-dependencies 不应该干扰我的 pom。”
我过去对此有些摸索,但永远无法让专家做我想做的事。我很确定简短的答案是“不”,但我将详细说明我所尝试的内容。
我为具有两次执行的程序集插件创建了pluginManagement 条目,每个执行都有唯一的ID 和配置。然后,在插件部分的程序集插件中,我添加了一个执行部分,其中只有一个执行,其 id 与我真正想要运行的执行的 id 相匹配。它仍然运行两者。
我为程序集插件创建了一个pluginManagement 条目,其中一次执行具有唯一的id 和配置。然后,在插件部分,我为程序集插件创建了一个条目,其中包含一次执行以及不同的 ID 和配置。它仍然运行两者。
我为程序集插件创建了一个pluginManagement 条目,其中一次执行具有唯一的ID 和配置。然后,在插件部分,我为具有一次执行和相同 id 的程序集插件创建了一个条目,这次指定了完全不同的配置。它显然将两种配置合并在一起并产生了两种配置的结果。注意:pluginManagement 部分中的配置使用了描述符条目,而plugins 部分中的配置使用了descriptorRef 条目。我尝试在插件部分的配置中添加一个空描述符条目,希望它能够覆盖(并基本上消除)在pluginManagement部分中指定的描述符的使用,但没有这样的运气。
我相信maven将始终将父插件与子插件合并,并且本质上不会覆盖任何内容,贪婪地合并匹配的标签(更多是更好的哲学,因此它不会选择一个标签的子元素而不是另一个标签的子元素)。
就这一理念而言,程序集插件可以帮助您构建自定义工件(在 Maven 中,每个项目都应该生成一个主要工件,不包括源分类器等),因此,如果多个子项需要使用程序集插件,您可以只会将它们共有的内容放入父 pom 中。如果您没有所有 maven-assemble-plugin 配置/执行所共有的任何内容,我认为您需要将程序集插件配置移动到每个子项目。
re:"is there a way that i can override parent poms definition? i mean is it possible to ignore parent pom definition and had my own descriptor so that jar-with-dependencies should not interfere my pom."
I've fumbled around with this a bit in the past, and could never quite get maven to do what I wanted. I'm pretty sure the short answer is "no", but I'll elaborate on what I've tried.
I created pluginManagement entry for the assembly plugin with two executions, each with a unique ID and configuration. Then in the assembly plugin in the plugins section, I added an executions section with ONLY one execution with an id matching the id of the execution I really wanted to run. It still ran both.
I created a pluginManagement entry for the assembly plugin with one execution with a unique id and configuration. Then in the plugins section I created an entry for the assembly plugin with one execution and a different id and configuration. It still ran both.
I created a pluginManagement entry for the assembly plugin with one execution with a unique id and configuration. Then in the plugins section I created an entry for the assembly plugin with one execution and the same id, this time specifying a completely different configuration. It apparently merged the two configurations together and produced the result of both of the configurations. Note: the configuration in the pluginManagement section used a descriptor entry, and the one in the plugins section used a descriptorRef entry. I tried adding an empty descriptors entry to the configuration in the plugins section hoping it would override (and essentially wipe out) the usage of the descriptor specified in the pluginManagement section, but no such luck.
I believe maven will always merge the parent plugins with child plugins and essentially overwrites nothing, greedily merging matching tags (more is better philosophy, so it doesn't choose the subelements of one tag over the subelements of another).
As far as the philosophy goes, the assembly plugin is there to help you build custom artifacts (and in maven each project should produce one main artifact, not counting sources classifiers, etc.), so if multiple children need to use the assembly plugin you would only put what is common to all of them in the parent pom. If you don't have anything that is common to all of the maven-assembly-plugin configurations/executions, I think you need to move the assembly plugin configuration to each of the child projects.
关于 Maven 正在执行的所有配置继承,Kevin 的回答无需添加太多内容。但是,如果您可以更改父 POM(不影响其行为),则可以选择如下:
可以在这里找到这样的示例:
https: //github.com/demobox/jar-with-deps-vs-spi/blob/master/pom.xml
在那里,默认值在“with-services-handler”配置文件中被覆盖,而不是子 POM ,但机制应该是相同的。
Not much to add to Kevin's answer regarding all the configuration inheritance that Maven is doing. However, if you can change the parent POM (without affecting it's behaviour) one option is the following:
An example of this can be found here:
https://github.com/demobox/jar-with-deps-vs-spi/blob/master/pom.xml
There, the default is overridden in the 'with-services-handler' profile rather than a child POM, but the mechanism should be the same.