Lib39/forge/build.gradle

231 lines
7.5 KiB
Groovy

plugins {
id 'multiloader-loader'
id 'net.neoforged.moddev.legacyforge'
}
mixin {
add(sourceSets.main, "${mod_id}.refmap.json")
config("${mod_id}.mixins.json")
config("${mod_id}.forge.mixins.json")
}
def commonResources = project(':common').file('src/main/resources/').getAbsolutePath()
def forgeResources = file('src/main/resources/').getAbsolutePath()
def forgeBuildResources = file('build/resources/main/').getAbsolutePath()
def commonBuildResources = project(':common').file('build/resources/main/').getAbsolutePath()
def generatedOutput = project(':common').file('src/generated/resources/').getAbsolutePath()
legacyForge {
version = "${minecraft_version}-${forge_version}"
validateAccessTransformers = true
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
if (at.exists()) {
accessTransformers = ["src/main/resources/META-INF/accesstransformer.cfg"]
}
parchment {
minecraftVersion = parchment_minecraft
mappingsVersion = parchment_version
}
runs {
client {
client()
devLogin = true
programArguments.addAll(
'--mod', project.mod_id,
'--all',
'--existing', forgeResources,
'--existing', commonResources,
'--existing', forgeBuildResources,
'--existing', commonBuildResources
)
}
data {
data()
// 使用之前定义的变量
programArguments.addAll(
'--mod', project.mod_id,
'--all',
'--output', generatedOutput,
'--existing', forgeResources,
'--existing', commonResources,
'--existing', forgeBuildResources,
'--existing', commonBuildResources
)
}
server {
server()
programArguments.addAll(
'--mod', project.mod_id,
'--all',
'--existing', forgeResources,
'--existing', commonResources,
'--existing', forgeBuildResources,
'--existing', commonBuildResources
)
}
}
mods {
"${mod_id}" {
sourceSet sourceSets.main
}
}
}
sourceSets.main.resources.srcDir project(':common').file('src/generated/resources')
dependencies {
compileOnly project(":common")
annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT:processor")
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:0.2.0"))
modImplementation(group: 'tschipp.carryon', name: 'carryon-forge-1.20.1', version: '2.1.2.7') {
transitive = false
}
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.2.0"))
}
jar {
finalizedBy('reobfJar')
manifest.attributes([
"MixinConfigs": "${mod_id}.mixins.json,${mod_id}.forge.mixins.json"
])
}
// 配置sourceJar任务
tasks.named('sourcesJar', Jar) {
dependsOn classes
dependsOn project(':common').tasks.named('sourcesJar') // 显式依赖common的source
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveClassifier.set('sources')
from sourceSets.main.allSource
from project(':common').sourceSets.main.allSource
}
// 配置javadoc任务
tasks.named('javadoc', Javadoc) {
source project(':common').sourceSets.main.allJava
source sourceSets.main.allJava
classpath = configurations.compileClasspath
classpath += project(':common').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} ${minecraft_version} ${version} Javadoc")
}
// 配置javadocJar任务
tasks.named('javadocJar', Jar) {
dependsOn javadoc
dependsOn project(':common').tasks.named('javadoc') // 显式依赖common的javadoc
archiveClassifier.set('javadoc')
from javadoc.destinationDir
from project(':common').javadoc.destinationDir
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// 确保build任务包含所有需要的jar
tasks.named('build') {
dependsOn tasks.named('sourcesJar')
dependsOn tasks.named('javadocJar')
}
// 处理reobf
tasks.named('reobfJar') {
dependsOn tasks.named('sourcesJar')
dependsOn tasks.named('javadocJar')
}
// 发布配置
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = "${mod_id}-forge-${minecraft_version}"
artifacts.clear()
artifact(tasks.named('reobfJar').get()) {
builtBy tasks.named('reobfJar')
}
artifact(tasks.named('sourcesJar').get()) {
builtBy tasks.named('sourcesJar')
classifier = 'sources'
}
artifact(tasks.named('javadocJar').get()) {
builtBy tasks.named('javadocJar')
classifier = 'javadoc'
}
pom {
name = 'Lib39'
description = 'Lib39 is a general-purpose dependency library for Minecraft mods.'
url = 'https://github.com/3944Realms/lib39'
properties = [
'minecraft.version': project.minecraft_version,
'mod.version': project.version,
'forge.version': project.forge_version,
'java.version': '17'
]
licenses {
license {
name = 'MIT'
url = 'https://raw.githubusercontent.com/3944Realms/lib39/refs/heads/main/LICENSE'
distribution = 'repo'
}
}
developers {
developer {
id = 'R3944Realms'
name = "${mod_author}"
email = 'f256198830@hotmail.com'
}
}
scm {
connection = 'scm:git:https://github.com/3944Realms/lib39.git'
developerConnection = 'scm:git:ssh://git@github.com:3944Realms/lib39.git'
url = 'https://github.com/3944Realms/lib39'
tag = 'main'
}
issueManagement {
system = 'GitHub'
url = 'https://github.com/3944Realms/lib39/issues'
}
}
}
}
}
// 处理资源
processResources {
from project(':common').sourceSets.main.resources
inputs.property "version", project.version
inputs.property "minecraft_version", minecraft_version
inputs.property "forge_version", forge_version
inputs.property "mod_id", mod_id
inputs.property "mod_name", mod_name
inputs.property "description", description
inputs.property "mod_author", mod_author
filesMatching(['META-INF/mods.toml', 'pack.mcmeta', "*.mixins.json"]) {
expand([
version: project.version,
minecraft_version: minecraft_version,
forge_version: forge_version,
mod_id: mod_id,
mod_name: mod_name,
description: description,
mod_author: mod_author
])
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}