简体   繁体   English

如何从 gradle 项目依赖项中排除 META-INF?

[英]How do you exclude META-INF from a gradle project dependency?

I've got two sibling projects ProjectA and ProjectB that are both under Parent .我有两个兄弟项目ProjectAProjectB都在Parent下。 Parent is basically only a folder, and has common build.gradle settings for both child projects. Parent 基本上只是一个文件夹,并且对于两个子项目都有共同的 build.gradle 设置。

ProjectB depends on code in ProjectA at compile time, but ProjectA is built separately and contains a META-INF directory. ProjectB 在编译时依赖于 ProjectA 中的代码,但 ProjectA 是单独构建的,并包含一个 META-INF 目录。 When building ProjectB I get a java.lang.SecurityException: Invalid signature file digest for Manifest main attributes .构建 ProjectB 时,我收到一个java.lang.SecurityException: Invalid signature file digest for Manifest main attributes As you can see below, I've removed the zipTree calls from ProjectB and am unsure of how to fix this problem.正如您在下面看到的,我已从 ProjectB 中删除了 zipTree 调用,但不确定如何解决此问题。 Would greatly appreciate some assistance.非常感谢一些帮助。

Please keep in mind, both projects must build their own JAR and ProjectA must shade the two dependencies seen below.请记住,两个项目都必须构建自己的 JAR,而 ProjectA 必须遮蔽下面看到的两个依赖项。

Parent settings.gradle:父设置.gradle:

rootProject.name = "Parent"
include ":ProjectA", ":ProjectB"

Parent build.gradle:父 build.gradle:

allprojects {
    buildscript {
        repositories {
            jcenter()
            maven {
                name = "forge"
                url = "https://files.minecraftforge.net/maven"
            }
            maven {
                name = "sponge"
                url = "https://repo.spongepowered.org/maven"
            }
        }
        dependencies {
            classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT"
            classpath "org.spongepowered:mixingradle:0.6-SNAPSHOT"
        }
    }

    repositories {
        mavenCentral()
        maven {
            name = 'spongepowered-repo'
            url = 'https://repo.spongepowered.org/maven'
        }
        maven {
            name = 'jitpack-repo'
            url = 'https://jitpack.io'
        }
    }

    configurations {
        shade
        compile.extendsFrom(shade)
    }
}

ProjectA build.gradle: ProjectA build.gradle:

apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: 'org.spongepowered.mixin'

version = project.modVersion
group = project.modGroup

minecraft {
    version = "${project.mcVersion}-${project.forgeVersion}"
    runDir = "run"

    // the mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   snapshot are built nightly.
    // stable_#            stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not always work.
    // simply re-run your setup task after changing the mappings to update your workspace.
    mappings = project.mcpVersion
    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

    replace("@MOD_VERSION@", project.modVersion)
    replace("@MOD_ID@", project.modId)
    replace("@MOD_NAME@", project.modBaseName)
    replace("@MOD_ACCEPTED@", "[${project.modAcceptedVersions}]")
    replaceIn "${project.modBaseName}.java"
}

mixin {
    defaultObfuscationEnv searge
    add sourceSets.main, "mixins.${project.modId}.refmap.json"
}

dependencies {
    shade("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
        // Mixin includes a lot of dependencies that are too up-to-date
        exclude module: 'launchwrapper'
        exclude module: 'guava'
        exclude module: 'gson'
        exclude module: 'commons-io'
        exclude module: 'log4j-core'
    }

    shade group: 'org.yaml', name: 'snakeyaml', version: '1.6'
}

jar {
    from(configurations.shade.collect { it.isDirectory() ? it : zipTree(it) })
    //from (configurations.provided.collect { entry -> zipTree(entry) })

    manifest {
        attributes(
                'FMLAT': "${project.modId}_at.cfg",
                'MixinConfigs': "mixins.${project.modId}.json",
                'TweakOrder': '0',
                'TweakClass': "${project.modGroup}.${project.modId}.tweaker.${project.modBaseName}Tweaker",
                'Main-Class': 'OpenErrorMessage'
        )
    }
}

processResources {
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include "**/*.info"
        include "**/*.properties"

        // replace version and mcversion
        expand "version": project.version, "mcversion": project.minecraft.version
    }

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

ProjectB build.gradle:项目B build.gradle:

apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'org.spongepowered.mixin'

version = project.modVersion
group = project.modGroup

minecraft {
    version = "${project.mcVersion}-${project.forgeVersion}"
    runDir = "run"

    // the mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   snapshot are built nightly.
    // stable_#            stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not always work.
    // simply re-run your setup task after changing the mappings to update your workspace.
    mappings = project.mcpVersion
    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

    replace("@MOD_VERSION@", project.modVersion)
    replace("@MOD_ID@", project.modId)
    replace("@MOD_NAME@", project.modBaseName)
    replace("@MOD_ACCEPTED@", "[${project.modAcceptedVersions}]")
    replaceIn "${project.modBaseName}.java"
}

mixin {
    defaultObfuscationEnv searge
    add sourceSets.main, "mixins.${project.modId}.refmap.json"
}

dependencies {
    /*shade("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
        // Mixin includes a lot of dependencies that are too up-to-date
        exclude module: 'launchwrapper'
        exclude module: 'guava'
        exclude module: 'gson'
        exclude module: 'commons-io'
        exclude module: 'log4j-core'
    }*/

    compile project(":SkyblockRecords")
}

jar {
    archiveName = "${project.modBaseName}-${project.version}-for-MC-1.12.x.jar"

    /*from(configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }) {
        exclude 'META-INF', 'META-INF/**'
    }*/

    manifest {
        attributes(
                'FMLAT': "${project.modId}_at.cfg",
                'MixinConfigs': "mixins.${project.modId}.json",
                'TweakOrder': '0',
                'TweakClass': "${project.modGroup}.${project.modId}.tweaker.${project.modBaseName}Tweaker",
                'Main-Class': 'OpenErrorMessage'
        )
    }
}

processResources {
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include "**/*.info"
        include "**/*.properties"

        // replace version and mcversion
        expand "version": project.version, "mcversion": project.minecraft.version
    }

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

Thanks to a comment by Bjorn Vester on the question, I've solved the problem.感谢 Bjorn Vester 对这个问题的评论,我已经解决了这个问题。 The answer is to move the jar's configurations shade collect call to ProjectA.答案是将 jar 的配置阴影收集调用移动到 ProjectA。

// Move this to the jar section of ProjectA
from(configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }) {
    exclude 'META-INF', 'META-INF/**'
}

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

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