maven-shade-plugin将不包含依赖项

问题描述 投票:0回答:1

我有一个令人毛骨悚然的问题。我正在尝试使用maven-shade-plugin将带有嵌入式tomcat服务器的spring mvc应用程序打包到单个jar中。我已经尝试过类似的任务。曾经尝试对我的pom文件使用类似的配置。不幸的是,打包后的罐子只包含我创建的类。清单确实提到了所有依赖项。我认为这可能是Maven的问题,但是尝试了另一个项目,并且插件似乎正常工作。这是我的POM的相关片段:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.wojto</groupId>
  <artifactId>wmcase</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>WMcase Maven Webapp</name>

    <properties>
        <springframework.version>5.2.3.RELEASE</springframework.version>
        <springsecurity.version>5.1.4.RELEASE</springsecurity.version>
        <tomcat.version>9.0.30</tomcat.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

(...)

    <build>
        <finalName>wmcase</finalName>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.2.1</version>
                    <configuration>
                        <createDependencyReducedPom>true</createDependencyReducedPom>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>

                    </configuration>

                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <shadedArtifactAttached>true</shadedArtifactAttached>
                                <transformers>
                                    <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                    <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <manifestEntries>
                                            <Main-Class>com.wojto.wmcase.application.Application</Main-Class>
                                        </manifestEntries>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.wojto.wmcase.application.Application</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

    </build>
</project>
maven dependencies maven-shade-plugin packing uberjar
1个回答
0
投票

删除标签<pluginManagement></pluginManagement>,并保留其余部分,否则将无法正常工作。

技巧只是因为pluginManagement顾名思义是插件的管理,通常是版本,有时是配置。这意味着在pluginManagement中定义的插件将永远不会执行。

[如果您希望使用<plugins></plugins>来执行插件

另请参见文档:http://maven.apache.org/pom.html

© www.soinside.com 2019 - 2024. All rights reserved.