简体   繁体   English

Maven Shade插件未将依赖项类文件放入jar

[英]Maven shade plugin isn't placing dependency class files into jar

My Maven project uses an external library as a dependency, com.sk89q.intake:intake , which I'm trying to package into my jar via the maven-shade-plugin . 我的Maven项目使用外部库com.sk89q.intake:intake作为依赖项,我试图通过maven-shade-plugin将其打包到jar中。 When building the project, the resulting jar does not contain any of the class files of com.sk89q.intake:intake . 在构建项目时,生成的jar不包含com.sk89q.intake:intake任何类文件。 During the build process, I get this message, but the build continues on and succeeds: 在构建过程中,我收到此消息,但是构建继续并成功:

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

Why is this happening? 为什么会这样呢? I'm able to download, access, and use the dependency in my project, so there shouldn't be anything wrong with naming of the artifact. 我可以下载,访问和使用项目中的依赖项,因此,对工件的命名应该没有任何问题。

pom.xml 的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>

As you can see, I am including the com.sk89q.intake:intake artifact. 如您所见,我包括com.sk89q.intake:intake工件。 I have looked through the maven-shade-plugin documentation and don't see what I'm doing wrong. 我浏览了maven-shade-plugin文档,但没有发现我做错了什么。 The naming is consistent with everything I have found online; 命名与我在网上找到的所有内容一致; that is, groupId:artifactId . groupId:artifactId

I have also tried building without the <relocation> class relocation tags to see if they were interfering. 我还尝试了构建没有<relocation>类重定位标记的代码,以查看它们是否在干扰。

It may be useful to know that I'm using M2Eclipse and building with the clean install goals. 了解我正在使用M2Eclipse并使用全新clean install目标进行构建可能会很有用。

The problem is that your are declaring the com.sk89q.intake:intake dependency with the provided scope. 问题是您正在使用provided范围声明com.sk89q.intake:intake依赖项。

Provided dependency are expected to be provided by the container at runtime so the maven-shade-plugin will not add it to your shaded jar. 预计容器将在运行时提供所提供的依赖关系,因此maven-shade-plugin不会将其添加到已着色的jar中。 As such, you need to remove the provided scope from the dependency declaration: 因此,您需要从依赖项声明中删除provided范围:

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

Relevant build log after this change: 更改后的相关构建日志:

[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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM