为什么 Maven 阴影会跳过 MCCoroutine 库中的文件

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

运行我的 Spigot 插件(使用 Kotlin 和 Maven 构建)时,我收到有关缺少类的错误。

我的 .jar 中缺少文件“com.github.shynixn.mccoroutine.bukkit.impl.MCCoroutineImpl”。正如在 jar 结构中运行命令

ls -R
时所看到的那样。但文件夹“impl”确实包含一个名称奇怪的文件,这可能与此有关。
./com/github/shynixn/mccoroutine/bukkit/impl: 'CoroutineSessionImpl$init$inlined$Runnable$1.class'

如何解决这个问题?

我联系了图书馆所有者这个问题

实施细节:

  • 科特林 v1.9.0
  • Kotlin 插件 232-1.9.20-release-507-IJ10072.27
  • Maven 阴影插件 v3.5.1(也出现在 v3.5.0 上)
  • Maven编译器插件v3.11.0
  • 我正在使用
    minimizeJar

构建我的 Spigot 插件(使用 Kotlin 和 Maven 构建)时 - Maven 不会记录任何错误。这是输出:

[INFO] Including com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:jar:2.13.0 in the shaded jar. [INFO] Including com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:jar:2.13.0 in the shaded jar.

当我运行插件时,我收到以下错误:

java.lang.RuntimeException: Failed to load MCCoroutine implementation. Shade mccoroutine-bukkit-core into your plugin.
        at com.github.shynixn.mccoroutine.bukkit.MCCoroutineKt$mcCoroutine$2.invoke(MCCoroutine.kt:20) ~[?:?]
        at com.github.shynixn.mccoroutine.bukkit.MCCoroutineKt$mcCoroutine$2.invoke(MCCoroutine.kt:15) ~[?:?]
        at me.sd_master92.kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) ~[?:?]
        at com.github.shynixn.mccoroutine.bukkit.MCCoroutineKt.getMcCoroutine(MCCoroutine.kt:15) ~[?:?]
        at com.github.shynixn.mccoroutine.bukkit.MCCoroutineKt.getMinecraftDispatcher(MCCoroutine.kt:40) ~[?:?]
        at com.github.shynixn.mccoroutine.bukkit.MCCoroutineKt.launch$default(MCCoroutine.kt:85) ~[?:?]
        at me.sd_master92.customvoting.CV.enable(CV.kt:53) ~[?:?]
        at me.sd_master92.core.plugin.CustomPlugin.onEnable(CustomPlugin.kt:42) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:266) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R2.CraftServer.enablePlugin(CraftServer.java:548) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at org.bukkit.craftbukkit.v1_20_R2.CraftServer.enablePlugins(CraftServer.java:462) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at org.bukkit.craftbukkit.v1_20_R2.CraftServer.reload(CraftServer.java:970) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at org.bukkit.Bukkit.reload(Bukkit.java:834) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R2.CraftServer.dispatchCommand(CraftServer.java:879) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at org.bukkit.craftbukkit.v1_20_R2.CraftServer.dispatchServerCommand(CraftServer.java:864) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at net.minecraft.server.dedicated.DedicatedServer.bf(DedicatedServer.java:412) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:388) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1179) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:996) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:298) ~[spigot-1.20.2-R0.1-SNAPSHOT.jar:3943-Spigot-7de1049-8e162d0]
        at java.lang.Thread.run(Thread.java:1583) ~[?:?]
Caused by: java.lang.ClassNotFoundException: com.github.shynixn.mccoroutine.bukkit.impl.MCCoroutineImpl
        at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:160) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:112) ~[spigot-api-1.20.2-R0.1-SNAPSHOT.jar:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:?]
        at java.lang.Class.forName(Class.java:421) ~[?:?]
        at java.lang.Class.forName(Class.java:412) ~[?:?]
        at com.github.shynixn.mccoroutine.bukkit.MCCoroutineKt$mcCoroutine$2.invoke(MCCoroutine.kt:17) ~[?:?]
        ... 24 more
kotlin maven kotlin-coroutines maven-shade-plugin spigot
1个回答
0
投票

此问题的解决方案(不是最干净的)是将这个包中的所有文件包含到阴影 .jar 中。

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.0</version>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>com.github.shynixn.mccoroutine:mccoroutine-bukkit-core</artifact>
                            <includes>
                                <include>*/**</include>
                            </includes>
                        </filter>
                    </filters>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <minimizeJar>true</minimizeJar>
                        </configuration>
                    </execution>
                </executions>
                </configuration>```
© www.soinside.com 2019 - 2024. All rights reserved.