Maven程序集插件不能与pluginManagement一起使用 [英] maven assembly plugin is not working with pluginManagement

查看:134
本文介绍了Maven程序集插件不能与pluginManagement一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的maven-assembly-plugin配置,它工作正常.但是当我将所有插件添加到pluginManagement父标记中时,它不起作用.

Below is my configuration of maven-assembly-plugin and it's working fine.but when i am adding my all plugins inside the pluginManagement parent tag it's not working.

我不确定为什么它不起作用

I am not sure why it's not working

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>MyId</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptor>assemblyFile.xml</descriptor>
                        <appendAssemblyId>false</appendAssemblyId>
                    </configuration>
                </execution>
            </executions>
        </plugin>

推荐答案

您的 maven-assembly-plugin 不应包含在 pluginManagement 部分中.如果是,它将被忽略.构建不会抛出错误-不会创建可执行jar.然后,如果尝试运行它,将得到没有主清单属性...".

The execution section of your maven-assembly-plugin should not be contained in a pluginManagement section. If it is, it will be ignored. The build will not throw an error - just won't create an executable jar. Then you would get "no main manifest attribute..." if you try to run it.

pluginManagement 部分,通常在父" pom中定义,在各个模块之间共享插件配置.它可以指定版本和配置,并且可以确保版本与子pom匹配,但是不打算包含执行细节.

The pluginManagement section, generally defined in a "parent" pom, shares plugin configuration across modules. It can specify version and configuration and it ensures the version matches across child poms, but is not intended to contain execution details.

这是一个有效的示例,其中 pluginManagement 仅指定插件的版本(请记住, pluginManagement 通常位于单独的父pom中):

Here's a valid example where pluginManagement specifies only the plugin's version (just keep in mind the pluginManagement would typically be in a separate, parent, pom):

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.my.App</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是一个示例,其中 pluginManagement 具有插件的版本及其配置. 常规插件部分仅指定执行详细信息:

And here's an example where pluginManagement has the plugin's version and also its configuration. The regular plugin section specifies only the execution details:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.my.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

请注意,子poms可以覆盖 pluginManagement 定义

Note that child poms can override pluginManagement definitions.

另请参见问题及其答案.

See also this question and its answers.

这篇关于Maven程序集插件不能与pluginManagement一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆