如何从 gradle 项目依赖项中排除 META-INF?
How do you exclude META-INF from a gradle project dependency?
我有两个兄弟项目 ProjectA
和 ProjectB
,它们都在 Parent
下。 Parent 基本上只是一个文件夹,两个子项目都有共同的 build.gradle 设置。
ProjectB 在编译时依赖于 ProjectA 中的代码,但 ProjectA 是单独构建的并且
包含一个 META-INF 目录。构建 ProjectB 时,我得到一个 java.lang.SecurityException:清单主要属性 的签名文件摘要无效。正如您在下面看到的,我已经从 ProjectB 中删除了 zipTree 调用,并且不确定如何解决此问题。非常感谢您的帮助。
请记住,两个项目都必须构建自己的 JAR,ProjectA 必须隐藏下面看到的两个依赖项。
父级 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)
}
}
项目 A 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"
}
}
项目 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"
}
}
感谢 Bjorn Vester 对问题的评论,我已经解决了问题。答案是将 jar 的配置 shade collect 调用移动到 ProjectA。
// Move this to the jar section of ProjectA
from(configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF', 'META-INF/**'
}
我有两个兄弟项目 ProjectA
和 ProjectB
,它们都在 Parent
下。 Parent 基本上只是一个文件夹,两个子项目都有共同的 build.gradle 设置。
ProjectB 在编译时依赖于 ProjectA 中的代码,但 ProjectA 是单独构建的并且 包含一个 META-INF 目录。构建 ProjectB 时,我得到一个 java.lang.SecurityException:清单主要属性 的签名文件摘要无效。正如您在下面看到的,我已经从 ProjectB 中删除了 zipTree 调用,并且不确定如何解决此问题。非常感谢您的帮助。
请记住,两个项目都必须构建自己的 JAR,ProjectA 必须隐藏下面看到的两个依赖项。
父级 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)
}
}
项目 A 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"
}
}
项目 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"
}
}
感谢 Bjorn Vester 对问题的评论,我已经解决了问题。答案是将 jar 的配置 shade collect 调用移动到 ProjectA。
// Move this to the jar section of ProjectA
from(configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF', 'META-INF/**'
}