Как вы исключаете META-INF из зависимости от проекта? - PullRequest
1 голос
/ 30 марта 2020

У меня есть два родственных проекта ProjectA и ProjectB, которые оба под Parent. Родитель в основном является только папкой и имеет общие настройки build.gradle для обоих дочерних проектов.

ProjectB зависит от кода в ProjectA во время компиляции, но ProjectA создается отдельно и содержит каталог META-INF. При сборке ProjectB я получаю java .lang.SecurityException: неверный дайджест файла подписи для основных атрибутов манифеста . Как вы можете видеть ниже, я удалил вызовы zipTree из ProjectB и не уверен, как решить эту проблему. Буду очень признателен за помощь.

Пожалуйста, имейте в виду, что оба проекта должны создавать свои собственные JAR, а ProjectA должен затенять две зависимости, показанные ниже.

Parent settings.gradle:

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

Родительский 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:

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:

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"
    }
}

1 Ответ

1 голос
/ 01 апреля 2020

Благодаря комментарию Бьёрна Вестера по этому вопросу я решил проблему. Ответ заключается в том, чтобы переместить вызов jar для сбора настроек теней в ProjectA.

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