gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:41:12 34 4
gpt4 key购买 nike

我有两个兄弟项目 ProjectAProjectB,它们都在 Parent 下。 Parent 基本上只是一个文件夹,并且具有两个子项目的通用 build.gradle 设置。

ProjectB 在编译时依赖于 ProjectA 中的代码,但 ProjectA 是单独构建的并且包含一个 META-INF 目录。构建 ProjectB 时,我得到一个 java.lang.SecurityException: list 主要属性的签名文件摘要无效。正如您在下面看到的,我已经从 ProjectB 中删除了 zipTree 调用,并且不确定如何解决此问题。非常感谢一些帮助。

请记住,两个项目都必须构建自己的 JAR,并且 ProjectA 必须屏蔽下面看到的两个依赖项。

父设置.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"
}
}

项目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/**'
}

关于java - 如何从 gradle 项目依赖项中排除 META-INF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60922779/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com