我的Maven项目使用外部库作为依赖项com.sk89q.intake:intake,我正尝试通过maven-shade-plugin将其打包到jar中。生成项目时,生成的jar不包含com.sk89q.intake:intake的任何类文件。在构建过程中,我收到此消息,但是构建继续并成功:

[INFO] --- maven-shade-plugin:2.4.2:shade (default) @ EventManagerPlugin
[INFO] No artifact matching filter com.sk89q.intake:intake


为什么会这样呢?我可以在项目中下载,访问和使用依赖项,因此,对工件的命名应该没有任何问题。

pom.xml

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>deletethis.eventmanager</groupId>
    <artifactId>EventManagerPlugin</artifactId>
    <version>1.0.0-beta1</version>
    <repositories>
        <repository>
            <id>spigot-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
        <repository>
            <id>maven.sk89q.com</id>
            <url>http://maven.sk89q.com/repo/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
           <groupId>org.spigotmc</groupId>
           <artifactId>spigot-api</artifactId>
           <version>1.8.8-R0.1-SNAPSHOT</version>
           <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.bukkit</groupId>
            <artifactId>bukkit</artifactId>
            <version>1.8.8-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sk89q.intake</groupId>
            <artifactId>intake</artifactId>
            <version>4.2-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Built-By>deletethis</Built-By>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <artifact>com.sk89q.intake:intake</artifact>
                                    <includes>
                                        <include>com/sk89q/intake/**</include>
                                    </includes>
                                </filter>
                            </filters>
                            <relocations>
                                <relocation>
                                    <pattern>com.sk89q.intake</pattern>
                                    <shadedPattern>deletethis.eventmanager.lib.com.sk89q.intake</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>


如您所见,我包含了com.sk89q.intake:intake工件。我浏览了maven-shade-plugin文档,但看不到我在做什么错。命名与我在网上找到的所有内容一致;即groupId:artifactId

我还尝试了构建没有<relocation>类重定位标签的代码,以查看它们是否在干扰。

了解我正在使用M2Eclipse并使用clean install目标进行构建可能会很有用。

最佳答案

问题在于您正在声明com.sk89q.intake:intake范围的provided依赖项。

预期容器将在运行时提供提供的依赖关系,因此maven-shade-plugin不会将其添加到您的着色jar中。因此,您需要从依赖项声明中删除provided范围:

<dependency>
    <groupId>com.sk89q.intake</groupId>
    <artifactId>intake</artifactId>
    <version>4.2-SNAPSHOT</version>
</dependency>


更改后的相关构建日志:

[INFO] --- maven-shade-plugin:2.4.2:shade (default) @ test ---
[INFO] Including com.sk89q.intake:intake:jar:4.2-SNAPSHOT in the shaded jar.
[INFO] Including com.google.guava:guava:jar:18.0 in the shaded jar.
[INFO] Including com.google.code.findbugs:jsr305:jar:3.0.0 in the shaded jar.

10-06 05:57