-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
155 lines (133 loc) · 4.78 KB
/
build.gradle
File metadata and controls
155 lines (133 loc) · 4.78 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
plugins {
id 'java'
id 'application'
id 'com.diffplug.spotless' version '8.4.0'
}
group = 'com.cope.addonparser'
version = '0.1.0'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
// Mapping profile: selects which shim source dir is included in the main sourceSet.
// Run gradle with -PparserProfile=legacy to build the 1.21.x flavor; default is 26x.
ext.parserProfile = (project.findProperty('parserProfile') ?: '26x').toString().toLowerCase()
if (parserProfile != 'legacy' && parserProfile != '26x') {
throw new GradleException("Unknown parserProfile: ${parserProfile} (expected 'legacy' or '26x')")
}
def profileSourceDir = parserProfile == 'legacy' ? 'src/profile-legacy/java' : 'src/profile-26x/java'
def profileFixtureJarsDir = "fixtures/addons/jars/${parserProfile}"
repositories {
mavenCentral()
maven { url = uri('https://libraries.minecraft.net') }
maven { url = uri('https://repo.spongepowered.org/repository/maven-public') }
}
dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.3'
implementation 'org.ow2.asm:asm:9.9'
implementation 'org.ow2.asm:asm-commons:9.9'
implementation 'org.slf4j:slf4j-api:2.0.16'
runtimeOnly 'org.slf4j:slf4j-simple:2.0.16'
implementation 'org.apache.logging.log4j:log4j-api:2.24.3'
runtimeOnly 'org.apache.logging.log4j:log4j-core:2.24.3'
implementation 'com.google.code.gson:gson:2.11.0'
implementation 'com.mojang:brigadier:1.0.18'
implementation 'org.spongepowered:mixin:0.8.5'
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
jvmArgs '-noverify'
systemProperty 'addonparser.profile', parserProfile
systemProperty 'addonparser.fixtureJarsDir', profileFixtureJarsDir
}
application {
mainClass = 'com.cope.addonparser.cli.Main'
applicationDefaultJvmArgs = ['-noverify', "-Daddonparser.profile=${project.parserProfile}"]
}
tasks.named('run') {
jvmArgs '-noverify'
systemProperty 'addonparser.profile', parserProfile
}
sourceSets {
stubgen {
java {
srcDirs = ['src/stubgen/java']
}
}
main {
java {
srcDirs += ['src/generated/java', profileSourceDir]
}
}
}
dependencies {
stubgenImplementation 'org.ow2.asm:asm:9.9'
stubgenImplementation 'com.google.code.gson:gson:2.11.0'
}
tasks.register('generateStubs', JavaExec) {
classpath = sourceSets.stubgen.runtimeClasspath
mainClass = 'com.cope.addonparser.tools.StubGenerator'
args '--input-dir', profileFixtureJarsDir,
'--output-dir', 'src/generated/java',
'--manual-class-list', 'tools/manual_classes.txt',
'--manual-source-dirs', files('src/main/java', profileSourceDir).asPath,
'--profile', parserProfile
// Incremental support: declare inputs and outputs
inputs.dir(profileFixtureJarsDir)
inputs.file('tools/manual_classes.txt')
inputs.dir('src/main/java')
inputs.dir(profileSourceDir)
inputs.files(sourceSets.stubgen.output)
outputs.dir('src/generated/java')
}
tasks.named('compileJava') {
mustRunAfter tasks.named('generateStubs')
}
tasks.register('verifyGeneratedStubs') {
group = 'verification'
description = 'Regenerates stubs and fails if src/generated/java changes.'
dependsOn tasks.named('generateStubs')
doLast {
def output = new ByteArrayOutputStream()
exec {
commandLine 'git', 'status', '--porcelain', '--', 'src/generated/java'
standardOutput = output
}
def diff = output.toString('UTF-8').trim()
if (!diff.isEmpty()) {
throw new GradleException(
"Generated stubs are out of date. Run 'gradle generateStubs' and commit src/generated/java.\n${diff}"
)
}
}
}
// Only auto-generate stubs when explicitly requested or property is set
if (project.hasProperty('autoGenerateStubs')) {
compileJava.dependsOn tasks.named('generateStubs')
}
if (project.hasProperty('verifyGeneratedStubs') || 'true'.equalsIgnoreCase(System.getenv('CI'))) {
tasks.named('check') {
dependsOn tasks.named('verifyGeneratedStubs')
}
}
tasks.named('clean') {
doLast {
delete 'src/generated/java'
}
}
// AP-009: Spotless configuration for Google Java Style on manual sources
spotless {
ratchetFrom 'master'
java {
target 'src/main/java/**/*.java', 'src/test/java/**/*.java', 'src/stubgen/java/**/*.java',
'src/profile-legacy/java/**/*.java', 'src/profile-26x/java/**/*.java'
targetExclude 'src/generated/java/**'
googleJavaFormat('1.35.0')
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}