SuperLeadRope/build.gradle

461 lines
15 KiB
Groovy
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//noinspection GroovyAssignabilityCheck
//file:noinspection GroovyAssignabilityCheck
import proguard.gradle.ProGuardTask
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.guardsquare:proguard-gradle:7.7.0'
}
}
plugins {
id 'java'
id 'idea'
id 'java-library'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'net.neoforged.moddev.legacyforge' version '2.0.103'
}
// ===================== 基础配置 =====================
def enableProguard = project.hasProperty("enableProguard") && project.enableProguard.toBoolean()
tasks.named('wrapper', Wrapper).configure {
distributionType = Wrapper.DistributionType.BIN
}
group = mod_group_id
version = "${minecraft_version}-${mod_version}"
java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}
base {
archivesName = mod_id
}
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
// ===================== 仓库配置 =====================
repositories {
mavenCentral()
maven { url = "https://libraries.minecraft.net/" }
maven { url = "https://neoforged.forgecdn.net/releases" }
maven { url = "https://neoforged.forgecdn.net/mojang-meta" }
maven {
url "https://cursemaven.com"
content { includeGroup "curse.maven" }
}
maven {
name = "Progwml6"
url = "https://dvs1.progwml6.com/files/maven/"
}
maven {
name = "BlameJared"
url = "https://maven.blamejared.com/"
}
maven {
name = "ModMaven"
url = "https://modmaven.dev"
}
maven {
name = "Lucko"
url = "https://repo.lucko.me/"
content { includeModule 'me.lucko', 'spark-api' }
}
maven {
name = "KosmX"
url = "https://maven.kosmx.dev/"
}
maven {
name = "Curios"
url = "https://maven.theillusivec4.top/"
}
maven {
name = "GeckoLib"
url = "https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/"
content {
includeGroupByRegex("software\\.bernie.*")
includeGroup("com.eliotlash.mclib")
}
}
maven {
name = "LTD Maven"
url = "https://nexus.bot.leisuretimedock.top/repository/maven-public/"
}
flatDir { dir "libs" }
}
// ===================== Forge 配置 =====================
legacyForge {
version = "${minecraft_version}-${forge_version}"
accessTransformers = files("src/main/templates/META-INF/accesstransformer.cfg")
parchment {
minecraftVersion = minecraft_version
mappingsVersion = mapping_lasting_version
}
runs {
configureEach {
systemProperty 'forge.logging.console.level', 'debug'
systemProperty 'forge.logging.markers', 'REGISTRIES'
logLevel = org.slf4j.event.Level.DEBUG
}
client {
client()
systemProperty 'forge.enabledGameTestNamespaces', mod_id
}
clientAuth {
devLogin = true
client()
systemProperty 'forge.enabledGameTestNamespaces', mod_id
}
server {
server()
}
data {
data()
programArguments.addAll '--mod', mod_id, '--all',
'--output', file('src/generated/resources/').absolutePath,
'--existing', file('src/main/resources/').absolutePath
}
}
mods {
"${mod_id}" {
sourceSet sourceSets.main
}
}
}
// ===================== 源码与资源 =====================
sourceSets.main.resources {
srcDir 'src/generated/resources'
srcDir 'src/main/resources'
}
// ===================== 编译配置 =====================
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
// ===================== 依赖 =====================
configurations {
runtimeClasspath.extendsFrom localRuntime
proguardLibs {
canBeResolved = true
canBeConsumed = false
extendsFrom modCompileOnly
}
}
dependencies {
annotationProcessor ('org.spongepowered:mixin:0.8.5:processor')
modRuntimeOnly("curse.maven:debug-utils-forge-783008:5337491")
modCompileOnly("blank:curtain-1.20.1:1.3.2")
modRuntimeOnly("blank:curtain-1.20.1:1.3.2")
modImplementation("dev.kosmx.player-anim:player-animation-lib-forge:${player_anim_version}")
modImplementation("curse.maven:bendy-lib-623373:4550371")
modImplementation("software.bernie.geckolib:geckolib-forge-${minecraft_version}:${geckolib_version}")
implementation("com.eliotlash.mclib:mclib:20")
modCompileOnly("top.theillusivec4.curios:curios-forge:${curios_version}:api")
modCompileOnly("top.theillusivec4.curios:curios-forge:${curios_version}")
modRuntimeOnly("top.theillusivec4.curios:curios-forge:${curios_version}")
modCompileOnly("mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}")
modCompileOnly("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}")
modRuntimeOnly("mezz.jei:jei-${minecraft_version}-forge:${jei_version}")
modRuntimeOnly("curse.maven:spark-361579:4738952")
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.1"))
modImplementation("io.github.llamalad7:mixinextras-forge:0.4.1")
compileOnly ('me.lucko:spark-api:0.1-SNAPSHOT')
implementation 'org.ow2.asm:asm:9.6'
implementation 'org.ow2.asm:asm-tree:9.6'
implementation 'org.ow2.asm:asm-commons:9.6'
implementation 'org.ow2.asm:asm-util:9.6'
modCompileOnly("top.r3944realms.lib39:lib39:1.20.1-0.0.15:all@jar")
}
// ===================== 修复 Javadoc 任务 =====================
tasks.named('javadoc', Javadoc).configure {
group = 'documentation'
description = 'Generates full Javadoc for the mod.'
destinationDir = file("$buildDir/docs/javadoc")
// 明确指定源与类路径
source = sourceSets.main.allJava
classpath = sourceSets.main.compileClasspath
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
options.links("https://docs.oracle.com/en/java/javase/17/docs/api/")
options.memberLevel = JavadocMemberLevel.PUBLIC
options.addBooleanOption('Xdoclint:none', true)
options.addStringOption('doctitle', "${mod_id} ${mod_version} Javadoc")
}
// ===================== 普通 Javadoc =====================
tasks.register('javadocJar', Jar) {
archiveClassifier.set('javadoc')
from tasks.javadoc
dependsOn tasks.javadoc
}
tasks.register('apiJavadocJar', Jar) {
archiveClassifier.set('api-javadoc')
from tasks.javadoc
include "top/r3944realms/superleadrope/api/**/*"
dependsOn tasks.javadoc
}
// ===================== API Jarclass + java 混杂) =====================
tasks.register('apiJar', Jar) {
archiveClassifier.set('api')
manifest {
attributes 'FMLModType': 'GAMELIBRARY'
}
// 打包 class 和 java
from(sourceSets.main.allSource) // java
from(sourceSets.main.output) { // class
exclude 'assets/**', 'data/**'
}
include "top/r3944realms/superleadrope/api/**/*"
include "top/r3944realms/superleadrope/SuperLeadRopeAPI.*"
dependsOn classes
}
tasks.register('apiJavadoc', Javadoc) {
group = 'documentation'
description = 'Generates Javadoc for API package only.'
destinationDir = file("$buildDir/docs/api-javadoc")
source = sourceSets.main.allJava.matching {
include "top/r3944realms/superleadrope/api/**/*"
include "top/r3944realms/superleadrope/SuperLeadRopeAPI.java"
}
classpath = sourceSets.main.compileClasspath
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
options.links("https://docs.oracle.com/en/java/javase/17/docs/api/")
options.memberLevel = JavadocMemberLevel.PUBLIC
options.addBooleanOption('Xdoclint:none', true)
options.addStringOption('doctitle', "${mod_name} API ${mod_version} Javadoc")
}
tasks.register('javadocApiJar', Jar) {
archiveClassifier.set('api-javadoc')
from tasks.apiJavadoc
dependsOn tasks.apiJavadoc
}
// ===================== 主包完整 Jarclass + java =====================
tasks.register('fullJar', Jar) {
archiveClassifier.set('all') // Maven 上会是 -all.jar
from(sourceSets.main.allSource) // java
from(sourceSets.main.output) // class
// === 避免重复打包资源(即使混入其他 jar 时也不会重复) ===
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes([
'Specification-Title' : mod_id,
'Specification-Vendor' : mod_authors,
'Specification-Version' : '1',
'Implementation-Title' : project.name,
'Implementation-Version' : archiveVersion,
'Implementation-Vendor' : mod_authors,
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
])
}
dependsOn classes
}
// ===================== 主 Jar 与混淆 =====================
jar {
manifest {
attributes([
'Specification-Title' : mod_id,
'Specification-Vendor' : mod_authors,
'Specification-Version' : '1',
'Implementation-Title' : project.name,
'Implementation-Version' : archiveVersion,
'Implementation-Vendor' : mod_authors,
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
])
}
archiveFileName = "${mod_id}-${mod_version}-origin.jar"
// 可选:排除 API 类(如果你不想在主 jar 中包含 API
// exclude "top/r3944realms/superleadrope/api/**/*"
finalizedBy 'proguard'
}
tasks.register('proguard', ProGuardTask) {
onlyIf { enableProguard }
dependsOn tasks.jar
configuration 'proguard.pro'
libraryjars "${System.getProperty('java.home')}/jmods"
configurations.proguardLibs.resolve().each { file ->
libraryjars file.absolutePath
}
def inputJar = tasks.jar.archiveFile.get().asFile
injars inputJar
outjars "${buildDir}/libs/[NOTUSE]${mod_id}-${minecraft_version}-${mod_version}-proguard.jar"
doFirst {
copy {
from inputJar
into "${buildDir}/libs"
rename { "[NOTUSE]${mod_id}-${minecraft_version}-${mod_version}-origin.jar" }
}
}
inputs.files tasks.jar.archiveFile
finalizedBy 'reobfJar'
}
processResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range : minecraft_version_range,
forge_version : forge_version,
forge_version_range : forge_version_range,
loader_version_range : loader_version_range,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description,
mod_credits : mod_credits
]
inputs.properties replaceProperties
expand replaceProperties
from "src/main/templates"
into "build/generated/sources/modMetadata"
}
sourceSets.main.resources.srcDir generateModMetadata
legacyForge.ideSyncTask generateModMetadata
afterEvaluate {
tasks.named('reobfJar') {
if (enableProguard) {
dependsOn 'proguard'
input = file("${buildDir}/libs/[NOTUSE]${mod_id}-${minecraft_version}-${mod_version}-proguard.jar")
} else {
dependsOn 'jar'
input = tasks.jar.archiveFile.get().asFile
}
}
}
// ===================== 发布配置 =====================
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = mod_id
artifact fullJar
artifact apiJar
// 可选
artifact javadocJar
artifact apiJavadocJar
pom {
name = "${mod_id}"
description = "The API for ${mod_name}"
url = "https://github.com/3944Realms/SuperLeadMod"
licenses {
license {
name = mod_license
url = "https://www.gnu.org/licenses/gpl-3.0.en.html#license-text"
}
}
developers {
developer {
id = "${mod_id}"
name = mod_authors
}
}
}
}
}
repositories {
maven {
url "file://${project.projectDir}/mcmodsrepo"
}
maven {
name = 'LTDNexus'
url = 'https://nexus.bot.leisuretimedock.top/repository/maven-releases/'
credentials {
username = System.getenv('LTDNexusUsername') ?: ''
password = System.getenv('LTDNexusPassword') ?: ''
}
}
}
}
// ===================== 构建任务依赖 =====================
tasks.named('build') {
dependsOn apiJar, javadocApiJar
}
tasks.named('clean') {
delete fileTree(dir: "${project.projectDir}/mcmodsrepo")
}
// ===================== RenderDoc 运行支持 =====================
tasks.register("runWithRenderDoc", Exec) {
group = "minecraft"
description = "Run Minecraft with RenderDoc using runClientAuth configuration"
dependsOn "classes"
def renderDocCmd = file("RenderDoc_1.40_64/renderdoccmd.exe").absolutePath
def captureDir = file("$buildDir/renderdoc/capture").absolutePath
def runClientTask = tasks.named("runClientAuth", JavaExec).get()
def javaExecPath = new File(runClientTask.getJavaLauncher().get().metadata.installationPath.asFile, "bin/java.exe").absolutePath
def jdwpArgs = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
commandLine renderDocCmd, "capture", "--opt-hook-children", "--wait-for-exit",
"--working-dir", "$projectDir/run",
"--capture-file", "${captureDir}/minecraft_capture",
javaExecPath, jdwpArgs,
"@${buildDir}/moddev/clientRunVmArgs.txt",
"@${buildDir}/moddev/clientRunProgramArgs.txt"
environment "MOD_CLASSES", "superleadrope%%${buildDir}/classes/java/main;superleadrope%%${buildDir}/resources/main"
doFirst {
println "Using JVM: ${javaExecPath}"
println "RenderDoc capture dir: ${captureDir}"
}
}
// ===================== IDEA 支持 =====================
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}