Maven shade插件不会自动调用目标" package"

时间:2017-02-13 16:09:17

标签: maven plugins

我花了很多时间搞清楚如何调用Maven shade插件来构建一个超级jar(包含所有依赖项)。 我发现的大部分google-able信息(包括大量示例和Maven文档)都表明我所要做的就是将插件包含在pom.xml中:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
         </plugin>

然后&#34; mvn package&#34; (或最终调用&#34; package&#34;)的任何其他目标将自动触发此插件。

但无论我尝试什么 - 实际调用插件的唯一方法似乎是:运行&#34; mvn包阴影:阴影&#34; (这似乎打败了配置驱动的构建的目的)。无论是从Eclipse(STS版本:3.8.2.RELEASE)还是从命令行(Apache Maven 3.3.9)运行Maven,结果都相同。

我错过了什么吗?

UPD:已解决,请参阅GauravJ的回答。

1 个答案:

答案 0 :(得分:16)

我设法重现了你的问题。在你的pom.xml中,你必须有如下定义的插件,

<build>
<pluginManagement>
  <plugins>

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-shade-plugin</artifactId>
       <version>2.4.3</version>
       <executions>
       <execution>
            <phase>package</phase>
            <goals>
             <goal>shade</goal>
            </goals>
       </execution>
      </executions>
   </plugin>
   ....

  </plugins>
</pluginManagement>
</build>

而不是

<build>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-shade-plugin</artifactId>
       <version>2.4.3</version>
       <executions>
       <execution>
            <phase>package</phase>
            <goals>
             <goal>shade</goal>
            </goals>
       </execution>
      </executions>
   </plugin>
</build>

这可能会解决您的问题。