import java.util.jar.JarInputStream plugins { id 'java' id 'com.gradleup.shadow' version '9.0.0-rc1' } java { withSourcesJar() } version = "${minecraft_version}-${mod_version}" base { archivesName = project.archives_base_name } def jars = mod_loaders.split(',').toList() def add_outer = mod_add_outer.split(',').toList() def getManifestAttributes(File jarFile) { def manifestMap = [:] if (!jarFile.exists()) { return; } new JarInputStream(jarFile.newInputStream()).withCloseable { jarStream -> def manifest = jarStream.manifest if (manifest == null) { println "警告: ${jarFile.name} 中没有MANIFEST.MF" return manifestMap } manifest.mainAttributes.each { key, value -> manifestMap[key.toString()] = value.toString() } } return manifestMap } def getJarName(String s) { return rootProject.projectDir.toPath().resolve("mod_build/${mod_id}-${s}-${minecraft_version}-${mod_version}.jar") } def getJarNameOuther(String s, String v) { return rootProject.projectDir.toPath().resolve("mod_build/${mod_id}-${s}-${v}-${mod_version}.jar") } tasks.shadowJar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE mod_relocate_packs_id.split(",").toList().forEach { relocate("$it", "com.mingliqiye.minecraft.enchantment.conflict.library.$it") } dependsOn("sourcesJar") jars.forEach { t -> { dependsOn(":modsrc:${minecraft_version}:${t}:clean") dependsOn(":modsrc:${minecraft_version}:${t}:build") } } add_outer.forEach { t -> { dependsOn(":modsrc:${t}:clean") dependsOn(":modsrc:${t}:build") } } def allAttributes = [:] doFirst { jars.forEach { jar -> def file = getJarName(jar).toFile() if (file.exists()) { from(zipTree(file)) allAttributes.putAll(getManifestAttributes(file)) } } add_outer.forEach { t -> if (!t.isEmpty()) { def sp = t.split(":") def file = getJarNameOuther(sp[1], sp[0]).toFile() if (file.exists()) { from(zipTree(file)) allAttributes.putAll(getManifestAttributes(file)) } } } manifest.attributes(allAttributes) } archiveClassifier = '' from project(':common').sourceSets.main.output from { project(':common').configurations.runtimeClasspath .filter { it.exists() } .collect { it.isDirectory() ? it : zipTree(it) } } { exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'LICENSE', 'org/slf4j/**', "META-INF/maven/**", "META-INF/*LICENSE*", "META-INF/*NOTICE*", "META-INF/versions/**" } mergeServiceFiles() minimize() }