3

I've got two sibling projects ProjectA and ProjectB that are both under Parent. Parent is basically only a folder, and has common build.gradle settings for both child projects.

ProjectB depends on code in ProjectA at compile time, but ProjectA is built separately and contains a META-INF directory. When building ProjectB I get a 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. 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.

Parent settings.gradle:

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

Parent 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"
    }
}
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
Nahydrin
  • 13,197
  • 12
  • 59
  • 101
  • 1
    The code `/*from(configurations.shade ...` that you commented out in B should indeed exclude the META-INF folder from any shaded dependencies. Did you also try doing that for the shading in A? – Bjørn Vester Mar 31 '20 at 00:28
  • @BjørnVester I did not try it in ProjectA with the exclude parameters. Just tried this and it works. Thanks, I'll answer my own question. – Nahydrin Apr 01 '20 at 02:41

1 Answers1

6

Thanks to a comment by Bjorn Vester on the question, I've solved the problem. The answer is to move the jar's configurations shade collect call to ProjectA.

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