java 运行时未检测到Gradle Shadow插件依赖项

h5qlskok  于 2023-06-20  发布在  Java
关注(0)|答案(1)|浏览(100)

我正在做一个mod jar。我需要在最终的jar(org.apache.httpcomponents:httpasyncclient:4.1.5)中包含一个外部库。我正在使用Shadow插件来制作脂肪罐。但是,我无法正确地包含依赖项。
下面是我的build.gradle

buildscript {
    repositories {
        jcenter()
        maven {
            name = "forge"
            url = "https://files.minecraftforge.net/maven"
        }
    }
    dependencies {
        classpath "net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT"
    }
}
plugins {
    id "com.github.johnrengelman.shadow" version "4.0.4"
    id "java"
}
apply plugin: "net.minecraftforge.gradle.forge"

configurations {
    shade
    implementation.extendsFrom shade
}
repositories {
    jcenter()
}
dependencies {
    compile "org.apache.httpcomponents:httpasyncclient:4.1.5"
    shade "org.apache.httpcomponents:httpasyncclient:4.1.5"
}
shadowJar {
    classifier = ''
    configurations = [project.configurations.shade]
    finalizedBy 'reobfShadowJar'
}
reobf {
    shadowJar {}
}
tasks.build.dependsOn reobfShadowJar
shadowJar.finalizedBy('reobfShadowJar')
compileJava {
    sourceCompatibility = targetCompatibility = "1.8"
}
archivesBaseName = "${mod_id}"
version = "${mod_version}"
group = "com.<modid>.<modid>"
minecraft {
    version = "1.8.9-11.15.1.2318-1.8.9"
    runDir = "run"
    replace "@VERSION@", project.version
    replaceIn "<Modid>.java"
    mappings = "stable_22"
}
processResources {
    inputs.property "mod_version", project.version
    inputs.property "mc_version", project.minecraft.version
    from(sourceSets.main.resources.srcDirs) {
        include "mcmod.info"
        expand "mod_id":"${mod_id}",
                "mod_name":"${mod_name}",
                "mod_version":"${mod_version}",
                "mod_description":"${mod_description}",
                "mc_version":"${mc_version}"
    }
    from(sourceSets.main.resources.srcDirs) {
        exclude "mcmod.info"
    }
}

当我在IDEA中运行“Minecraft客户端”运行配置时,一切都按预期工作。但是,当我运行gradlew build时,在运行时,我得到Error: net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: /org/apache/http/concurrent/FutureCallback。为什么mod加载器找不到类,即使它们在jar中?(我可能做错了)。

bcs8qyzn

bcs8qyzn1#

我不得不重新安置org.apache。我想它干扰了现有的依赖性。之前这不起作用的原因是我使用了一个不存在的gradle.properties占位符。

buildscript {
    repositories {
        jcenter()
        maven {
            name = "forge"
            url = "https://files.minecraftforge.net/maven"
        }
    }
    dependencies {
        classpath "net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT"
    }
}
plugins {
    id "com.github.johnrengelman.shadow" version "4.0.4"
    id "java"
}
apply plugin: "net.minecraftforge.gradle.forge"
repositories {
    jcenter()
}
configurations {
    shade
    implementation.extendsFrom shade
}
dependencies {
    shade "org.apache.httpcomponents:httpasyncclient:4.1.5"
}
shadowJar {
    classifier = ""
    configurations = [project.configurations.shade]
    relocate("org.apache", "${group}.org.apache")
}
reobf {
    shadowJar {}
}
shadowJar.finalizedBy('reobfShadowJar')
compileJava {
    sourceCompatibility = targetCompatibility = "1.8"
}
archivesBaseName = "${mod_id}"
version = "${mod_version}"
group = "${group}"
minecraft {
    version = "1.8.9-11.15.1.2318-1.8.9"
    runDir = "run"
    replace "@VERSION@", project.version
    replaceIn "HighpixelSpeed.java"
    mappings = "stable_22"
}
processResources {
    inputs.property "mod_version", project.version
    inputs.property "mc_version", project.minecraft.version
    from(sourceSets.main.resources.srcDirs) {
        include "mcmod.info"
        expand "mod_id":"${mod_id}",
                "mod_name":"${mod_name}",
                "mod_version":"${mod_version}",
                "mod_description":"${mod_description}",
                "mc_version":"${mc_version}"
    }

    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude "mcmod.info"
    }
}

相关问题