2

嗨,我创建了一个程序集来压缩项目的图像,并将它连接到我的 pom 文件中的 package 阶段,这里的问题是当我执行“clean compile package”时,它正在创建我需要的 zip 文件以及一个文件 -jar- with-dependencies.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-dependencies.jar(58mb 这是我想要排除生成的依赖项)

4

4 回答 4

1

这里的问题是,当我执行“clean compile package”时,它正在创建我需要的 zip 文件以及我不想创建的文件 -jar-with-dependencies.jar。

如果您使用预定义的描述符-jar-with-dependencies.jar,通常会创建该文件。jar-with-dependencies您提供的代码段没有显示任何类似的内容并且按预期工作(在将其粘贴到测试 POM 之后):

$ ls 目标
archive-tmp Q4068706-1.0-SNAPSHOT-cat_image_resources.zip 测试类
类 Q4068706-1.0-SNAPSHOT.jar
maven-archiver 肯定报告

仔细检查您是否没有从父 POM 继承插件配置(例如使用mvn help:effective-pom),因为您提供的 XML 片段按预期工作。

于 2010-11-02T12:41:48.097 回答
0

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.

于 2010-11-01T15:14:46.220 回答
0

回复:“有没有一种方法可以覆盖父 pom 定义?我的意思是可以忽略父 pom 定义并拥有我自己的描述符,这样 jar-with-dependencies 就不会干扰我的 pom。”

过去我曾经摸索过这个问题,并且永远无法完全让 maven 做我想做的事。我很确定简短的回答是“不”,但我会详细说明我的尝试。

  1. 我为具有两个执行的程序集插件创建了 pluginManagement 条目,每个执行都有唯一的 ID 和配置。然后在插件部分的程序集插件中,我添加了一个执行部分,其中只有一个执行,其 id 与我真正想要运行的执行的 id 匹配。它仍然同时运行。

  2. 我为程序集插件创建了一个 pluginManagement 条目,其中一个执行具有唯一的 ID 和配置。然后在插件部分,我为程序集插件创建了一个条目,其中包含一次执行和不同的 id 和配置。它仍然同时运行。

  3. 我为程序集插件创建了一个 pluginManagement 条目,其中一个执行具有唯一的 ID 和配置。然后在插件部分,我为程序集插件创建了一个条目,其中包含一个执行和相同的 ID,这一次指定了一个完全不同的配置。它显然将两种配置合并在一起并产生了两种配置的结果。注意:pluginManagement 部分中的配置使用了描述符条目,而 plugins 部分中的配置使用了 descriptorRef 条目。我尝试在 plugins 部分的配置中添加一个空的描述符条目,希望它会覆盖(并基本上消除)pluginManagement 部分中指定的描述符的使用,但没有这样的运气。

我相信 maven 将始终将父插件与子插件合并,并且基本上不会覆盖任何内容,贪婪地合并匹配的标签(更多是更好的理念,因此它不会选择一个标签的子元素而不是另一个标签的子元素)。

就哲学而言,程序集插件可以帮助您构建自定义工件(在 Maven 中,每个项目都应该产生一个主要工件,不包括源分类器等),所以如果多个孩子需要使用程序集插件,你只会将它们所有人共同的东西放在父pom中。如果您没有所有 maven-assembly-plugin 配置/执行共有的任何东西,我认为您需要将程序集插件配置移动到每个子项目。

于 2010-11-04T23:42:07.500 回答
0

关于 Maven 正在执行的所有配置继承,Kevin 的回答并没有什么可补充的。但是,如果您可以更改父 POM(不影响其行为),则一个选项如下:

  1. 在父级中,为“默认”<execution> 定义链接到 <configuration> 元素中的 jar-with-dependencies 的 <descriptorRefs> 元素。即作为插件 <configuration> 的一部分。
  2. 在孩子中,跳过“默认”<execution>(这将禁用 jar-with-dependencies)并添加您自己的 <execution> 及其 <configuration>。

这方面的一个例子可以在这里找到:

https://github.com/demobox/jar-with-deps-vs-spi/blob/master/pom.xml

在那里,默认值在“with-services-handler”配置文件而不是子 POM 中被覆盖,但机制应该是相同的。

于 2011-07-25T18:55:58.030 回答