build.gradle 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. import org.apache.tools.ant.taskdefs.condition.Os
  2. import org.gradle.plugins.ide.eclipse.model.SourceFolder
  3. /*
  4. * This file was generated by the Gradle 'init' task.
  5. *
  6. * This generated file contains a sample Java project to get you started.
  7. * For more details take a look at the Java Quickstart chapter in the Gradle
  8. * User Manual available at https://docs.gradle.org/5.6.3/userguide/tutorial_java_projects.html
  9. */
  10. buildscript {
  11. repositories {
  12. maven { url 'https://plugins.gradle.org/m2/' }
  13. }
  14. dependencies {
  15. classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
  16. }
  17. }
  18. plugins {
  19. id 'java' // Apply the java plugin to add support for Java
  20. id 'java-library' // Apply the java-library plugin for API and implementation separation.
  21. id 'application' // Apply the application plugin to add support for building a CLI application
  22. id 'com.google.protobuf' version '0.8.18' // Apply the protobuf auto generator
  23. id 'com.diffplug.spotless' version '6.11.0' // Apply the Spotless linter plugin.
  24. id 'eclipse' // Eclipse Support
  25. id 'idea' // IntelliJ Support
  26. id 'maven-publish' // Support for publishing to Maven repositories.
  27. id 'signing' // Support for signing build artifacts.
  28. id 'io.freefair.lombok' version '6.6.1' // Lombok for delombok'ification
  29. }
  30. spotless {
  31. java {
  32. target fileTree(rootDir) {
  33. include '**/*.java'
  34. exclude '**/generated/**/*.*'
  35. exclude '.idea/**/*.*'
  36. }
  37. importOrder('io.grasscutter', '', 'java', 'javax', '\\#java', '\\#') // Configure import order.
  38. googleJavaFormat('1.15.0') // Use Google's Java formatter.
  39. formatAnnotations() // Reformat annotations.
  40. endWithNewline() // Ensure files end with a newline.
  41. indentWithTabs(2); indentWithSpaces(4) // Use 4 spaces for indentation.
  42. toggleOffOn() // Toggle off/on.
  43. }
  44. }
  45. compileJava.options.encoding = 'UTF-8'
  46. compileTestJava.options.encoding = 'UTF-8'
  47. sourceCompatibility = JavaVersion.VERSION_17
  48. targetCompatibility = JavaVersion.VERSION_17
  49. group = 'io.grasscutter'
  50. version = '1.7.4'
  51. java {
  52. withJavadocJar()
  53. withSourcesJar()
  54. }
  55. repositories {
  56. mavenCentral()
  57. }
  58. dependencies {
  59. // Additional JAR libraries.
  60. implementation fileTree(dir: 'lib', include: ['*.jar'])
  61. implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.5.8'
  62. // Logging libraries.
  63. implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.7'
  64. implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.4.7'
  65. implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.7'
  66. // Line reading libraries.
  67. implementation group: 'org.jline', name: 'jline', version: '3.21.0'
  68. implementation group: 'org.jline', name: 'jline-terminal-jna', version: '3.21.0'
  69. implementation group: 'net.java.dev.jna', name: 'jna', version: '5.10.0'
  70. // Java Netty for networking.
  71. implementation group: 'io.netty', name: 'netty-common', version: '4.1.86.Final'
  72. implementation group: 'io.netty', name: 'netty-handler', version: '4.1.86.Final'
  73. implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.86.Final'
  74. implementation group: 'io.netty', name: 'netty-transport-native-kqueue', version: '4.1.86.Final'
  75. // Serialization.
  76. implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0'
  77. implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.19.6'
  78. implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.14.2'
  79. implementation platform('com.fasterxml.jackson:jackson-bom:2.14.0')
  80. implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.14.2'
  81. // Reflections libraries.
  82. implementation group: 'org.reflections', name: 'reflections', version: '0.10.2'
  83. implementation group: 'com.esotericsoftware', name: 'reflectasm', version: '1.11.9'
  84. implementation group: 'com.github.davidmoten', name: 'rtree-multi', version: '0.1'
  85. // MongoDB object mapper.
  86. implementation group: 'dev.morphia.morphia', name: 'morphia-core', version: '2.2.7'
  87. // Utility libraries.
  88. implementation group: 'org.greenrobot', name: 'eventbus-java', version: '3.3.1'
  89. // implementation group: 'org.danilopianini', name: 'java-quadtree', version: '0.1.9'
  90. // Long-term scheduler.
  91. implementation group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.2'
  92. implementation group: 'org.quartz-scheduler', name: 'quartz-jobs', version: '2.3.2'
  93. // Lua script engine library.
  94. implementation group: 'org.luaj', name: 'luaj-jse', version: '3.0.1'
  95. // Java HTTP server library.
  96. implementation group: 'io.javalin', name: 'javalin', version: '5.5.0'
  97. // Java WebSocket server & client library.
  98. implementation group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.5.2'
  99. // Google Protocol Buffer definitions.
  100. // These are the raw '.proto' files.
  101. protobuf files('proto/')
  102. // Testing libraries.
  103. testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2'
  104. testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.2'
  105. testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.2'
  106. // HTTP client library for testing.
  107. testImplementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.10.0'
  108. // Lombok.
  109. compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.26'
  110. annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.26'
  111. testCompileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.26'
  112. testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.26'
  113. }
  114. configurations.configureEach {
  115. exclude group: 'org.slf4j', module: 'slf4j'
  116. }
  117. application {
  118. // Define the main class for the application
  119. getMainClass().set('emu.grasscutter.Grasscutter')
  120. }
  121. jar {
  122. exclude '*.proto'
  123. manifest {
  124. attributes 'Main-Class': 'emu.grasscutter.Grasscutter'
  125. }
  126. archiveBaseName = 'grasscutter'
  127. if (project.hasProperty('jarFilename')) {
  128. archiveFileName = "${jarFilename}.${archiveExtension}"
  129. }
  130. from {
  131. configurations.runtimeClasspath.collect {
  132. it.isDirectory() ? it : zipTree(it)
  133. }
  134. }
  135. duplicatesStrategy = DuplicatesStrategy.INCLUDE
  136. from('src/main/java') {
  137. include '*.xml'
  138. }
  139. destinationDirectory = file('.')
  140. }
  141. test {
  142. useJUnitPlatform()
  143. setMaxHeapSize('4G')
  144. }
  145. publishing {
  146. publications {
  147. mavenJava(MavenPublication) {
  148. artifactId = 'grasscutter'
  149. from components.java
  150. versionMapping {
  151. usage('java-api') {
  152. fromResolutionOf('runtimeClasspath')
  153. }
  154. usage('java-runtime') {
  155. fromResolutionResult()
  156. }
  157. }
  158. pom {
  159. name = 'Grasscutter'
  160. description = 'A server software reimplementation for an anime game.'
  161. url = 'https://github.com/Grasscutters/Grasscutter'
  162. licenses {
  163. license {
  164. name = 'The Apache License, Version 2.0'
  165. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  166. }
  167. }
  168. developers {
  169. developer {
  170. id = 'meledy'
  171. name = 'Meledy'
  172. email = 'meledy@grasscutter.io' // not a real email kek
  173. }
  174. }
  175. scm {
  176. connection = 'scm:git:git@github.com:Grasscutters/Grasscutter.git'
  177. developerConnection = 'scm:git:ssh://github.com:Grasscutters/Grasscutter.git'
  178. url = 'https://github.com/Grasscutters/Grasscutter'
  179. }
  180. }
  181. }
  182. }
  183. repositories {
  184. maven {
  185. if (version.endsWith('-dev')) {
  186. // Check if the action being ran is 'publish'.
  187. if (publish.state.executing) {
  188. println('Publishing to Ben4J-Maven')
  189. }
  190. url 'https://repo.4benj.com/releases'
  191. name '4benj-maven'
  192. credentials {
  193. username System.getenv('benj_maven_username')
  194. password System.getenv('benj_maven_token')
  195. }
  196. } else {
  197. // Check if the action being ran is 'publish'.
  198. if (publish.state.executing) {
  199. println('Publishing to Sonatype')
  200. }
  201. def releasesRepoUrl = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
  202. def snapshotsRepoUrl = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
  203. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  204. name = 'sonatype'
  205. credentials(PasswordCredentials)
  206. }
  207. }
  208. }
  209. }
  210. clean {
  211. delete protobuf.generatedFilesBaseDir
  212. }
  213. protobuf {
  214. protoc {
  215. // The artifact spec for the Protobuf Compiler
  216. artifact = 'com.google.protobuf:protoc:3.18.1'
  217. }
  218. generatedFilesBaseDir = "$projectDir/src/generated/"
  219. }
  220. sourceSets {
  221. main {
  222. proto {
  223. // In addition to the default 'src/main/proto'
  224. srcDir 'src/generated'
  225. }
  226. java {
  227. srcDir 'src/generated/main/java'
  228. }
  229. }
  230. }
  231. idea {
  232. module {
  233. // proto files and generated Java files are automatically added as
  234. // source dirs.
  235. // If you have additional sources, add them here:
  236. sourceDirs += file('/proto/')
  237. }
  238. }
  239. eclipse {
  240. classpath {
  241. file.whenMerged {
  242. cp -> cp.entries.add(new SourceFolder('src/generated/main/java', null))
  243. }
  244. }
  245. }
  246. signing {
  247. if (!version.endsWith('-dev')) {
  248. sign publishing.publications.mavenJava
  249. }
  250. }
  251. javadoc {
  252. options.encoding = 'UTF-8'
  253. if (JavaVersion.current().isJava9Compatible()) {
  254. options.addBooleanOption('html5', true)
  255. }
  256. // Add this to avoid warning caused by lack of comments in proto generated java files
  257. options.addStringOption('Xdoclint:none', '-quiet')
  258. exclude '**/*.md'
  259. exclude 'src/handbook/**/*.*'
  260. exclude 'src/generated/**/*.*'
  261. }
  262. tasks.register('injectGitHash') {
  263. def gitCommitHash = {
  264. try {
  265. return 'git rev-parse --verify --short HEAD'.execute().text.trim()
  266. } catch (ignored) {
  267. return 'GIT_NOT_FOUND'
  268. }
  269. }
  270. new File(projectDir, 'src/main/java/emu/grasscutter/BuildConfig.java').text = """package emu.grasscutter;
  271. public final class BuildConfig {
  272. public static final String VERSION = \"${version}\";
  273. public static final String GIT_HASH = \"${gitCommitHash()}\";
  274. }"""
  275. }
  276. tasks.register('generateHandbook') {
  277. if (project.hasProperty('skipHandbook')) {
  278. println('Skipping handbook generation.')
  279. return
  280. }
  281. // Resolve the NPM command.
  282. var npm = 'npm'
  283. if (Os.isFamily(Os.FAMILY_WINDOWS))
  284. npm = 'npm.cmd'
  285. def npmVersion = {
  286. try {
  287. return "${npm} --version".execute()
  288. } catch (ignored) {
  289. ignored.printStackTrace()
  290. return 'NPM_NOT_FOUND'
  291. }
  292. }
  293. // Check if Node is installed.
  294. if (npmVersion() == 'NPM_NOT_FOUND') {
  295. println('NPM is not installed. Skipping handbook generation.')
  296. } else {
  297. // Check if the handbook resources are present.
  298. if (!file('src/handbook/data/commands.json').exists()) {
  299. println('Command data was not found. Skipping handbook generation.')
  300. return
  301. }
  302. if (!file('src/handbook/data/avatars.csv').exists()) {
  303. println('Avatar data was not found. Skipping handbook generation.')
  304. return
  305. }
  306. if (!file('src/handbook/data/entities.csv').exists()) {
  307. println('Entity data was not found. Skipping handbook generation.')
  308. return
  309. }
  310. if (!file('src/handbook/data/items.csv').exists()) {
  311. println('Item data was not found. Skipping handbook generation.')
  312. return
  313. }
  314. if (!file('src/handbook/data/mainquests.csv').exists()) {
  315. println('Main quest data was not found. Skipping handbook generation.')
  316. return
  317. }
  318. if (!file('src/handbook/data/quests.csv').exists()) {
  319. println('Quest data was not found. Skipping handbook generation.')
  320. return
  321. }
  322. if (!file('src/handbook/data/scenes.csv').exists()) {
  323. println('Scene data was not found. Skipping handbook generation.')
  324. return
  325. }
  326. // Install dependencies before building.
  327. exec {
  328. workingDir 'src/handbook'
  329. commandLine npm, 'install'
  330. }
  331. // Build the handbook.
  332. exec {
  333. workingDir 'src/handbook'
  334. commandLine npm, 'run', 'build'
  335. }
  336. // Copy the handbook from /dist to /src/main/resources.
  337. copy {
  338. from 'src/handbook/dist/index.html'
  339. into 'src/main/resources/html'
  340. rename 'index.html', 'handbook.html'
  341. }
  342. }
  343. }
  344. processResources {
  345. dependsOn 'generateProto'
  346. }
  347. sourcesJar {
  348. dependsOn 'generateProto'
  349. }
  350. delombok {
  351. dependsOn 'generateProto'
  352. }
  353. // For terminal interacting in IDEA running
  354. run {
  355. standardInput = System.in
  356. }