-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
188 lines (155 loc) · 6.08 KB
/
build.gradle
File metadata and controls
188 lines (155 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "2.3.10"
id "org.jetbrains.dokka" version "2.1.0"
id 'net.fabricmc.fabric-loom' version "${loom_version}"
id 'top.katton.api-doc-generator'
}
version = project.mod_version
group = project.maven_group
base {
archivesName = project.archives_base_name
}
def isSnapshotVersion = provider { project.version.toString().endsWith('-SNAPSHOT') }
def nexusBaseUrl = providers.gradleProperty('nexusBaseUrl').orElse('https://nexus.mcfpp.top')
def nexusReleasesRepository = providers.gradleProperty('nexusReleasesRepository').orElse('maven-releases')
def nexusSnapshotsRepository = providers.gradleProperty('nexusSnapshotsRepository').orElse('maven-snapshots')
// Keep secrets out of the repository: provide nexusUsername/nexusPassword in ~/.gradle/gradle.properties
// or via ORG_GRADLE_PROJECT_nexusUsername / ORG_GRADLE_PROJECT_nexusPassword.
def nexusRepositoryUrl = provider {
def repositoryName = isSnapshotVersion.get() ? nexusSnapshotsRepository.get() : nexusReleasesRepository.get()
"${nexusBaseUrl.get().replaceAll('/+$', '')}/repository/${repositoryName}/"
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
}
// Root build will configure Architectury Loom for subprojects that apply it
subprojects {
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'maven-publish'
repositories {
mavenCentral()
maven { url = uri('https://maven.fabricmc.net/') }
}
publishing {
repositories {
mavenLocal()
maven {
name = 'privateNexus'
url = uri(nexusRepositoryUrl.get())
allowInsecureProtocol = false
credentials {
username = providers.gradleProperty('nexusUsername')
.orElse(providers.environmentVariable('NEXUS_USERNAME'))
.orNull
password = providers.gradleProperty('nexusPassword')
.orElse(providers.environmentVariable('NEXUS_PASSWORD'))
.orNull
}
}
}
}
afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
def publicationComponent = project.findProperty('useLeanMavenPublication') ? null : components.findByName('java')
if (publicationComponent != null) {
from publicationComponent
}
artifactId = "${rootProject.findProperty('archives_base_name')}-${project.name}"
}
}
}
}
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 25
}
tasks.withType(KotlinCompile).all {
kotlinOptions {
jvmTarget = 25
}
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
}
jar {
inputs.property "archivesName", project.base.archivesName
from("LICENSE") {
rename { "${it}_${inputs.properties.archivesName}"}
}
}
kattonApiDocs {
outputDir = layout.buildDirectory.dir('docs')
module('common') {
displayName = 'Common'
sourceRoots.from(project(':common').file('src/main/kotlin/top/katton/api'))
}
module('fabric') {
displayName = 'Fabric'
sourceRoots.from(project(':fabric').file('src/main/kotlin/top/katton/api'))
}
module('neoforge') {
displayName = 'NeoForge'
sourceRoots.from(project(':neoforge').file('src/main/kotlin/top/katton/api'))
}
}
// Fabric/Architectury/Loom 配置已移动到 fabric/build.gradle 中,fabric 模块自行应用和配置 loom 插件。
// 这样避免在根项目配置阶段尝试加载 loom 插件导致的解析问题。
// neoforge and common are regular JVM modules
project(':common') {
// common 不应用 loom,作为纯 JVM 库编译,运行时由子模块提供 Minecraft
}
project(':neoforge') {
// NeoForge 模块保留为普通 JVM 模块,运行时依赖 NeoForge
}
// existing tasks kept for root project
def datapackName = 'qwq'
def worldName = 'test'
def datapacksDir = layout.projectDirectory.dir("Katton-Example/${datapackName}")
def targetDatapacksDir = layout.projectDirectory.dir("run/saves/${worldName}/datapacks/${datapackName}")
sourceSets {
test {
java.srcDirs += ["Katton-Example/${datapackName}"]
kotlin.srcDirs += ["Katton-Example/${datapackName}"]
}
}
// 任务:将 Katton-Example/${datapackName} 复制并合并到 run/saves/${worldName}/datapacks/${datapackName}
// Katton-Example/${datapackName} 优先级更高,会覆盖目标目录中的同名文件
tasks.register('copyDatapacks', Copy) {
group = 'Katton'
description = "Copy and merge datapacks from Katton-Example/${datapackName} to run/saves/${worldName}/datapacks/${datapackName}"
from datapacksDir
into targetDatapacksDir
// 如果文件冲突,使用 Katton-Example/${datapackName} 的文件(覆盖目标文件)
duplicatesStrategy = DuplicatesStrategy.INCLUDE
// 显示复制的文件
eachFile { details ->
logger.lifecycle("Copying datapack: ${details.sourcePath}")
}
}
// 任务:清理并强制重新复制所有 datapacks
tasks.register('cleanDatapacks') {
group = 'Katton'
description = 'Clean target datapacks directory'
doFirst {
// 删除目标目录
def targetDir = targetDatapacksDir.asFile
if (targetDir.exists()) {
logger.lifecycle("Cleaning target directory: ${targetDir.absolutePath}")
delete targetDir
}
}
}
tasks.register('publishAllToPrivateNexus') {
group = 'publishing'
description = "Publish all subprojects to ${nexusRepositoryUrl.get()}."
dependsOn(subprojects.collect { ":${it.name}:publishAllPublicationsToPrivateNexusRepository" })
}