mirror of
https://github.com/CCBlueX/LiquidBounce.git
synced 2025-09-06 17:50:42 +00:00
407 lines
14 KiB
Groovy
407 lines
14 KiB
Groovy
/*
|
|
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
|
|
*
|
|
* Copyright (c) 2015 - 2025 CCBlueX
|
|
*
|
|
* LiquidBounce is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* LiquidBounce is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
|
|
import groovy.json.JsonOutput
|
|
import groovy.json.JsonSlurper
|
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
|
|
|
def getContributors(repoOwner, repoName) {
|
|
def url = "https://api.github.com/repos/${repoOwner}/${repoName}/stats/contributors"
|
|
def connection = (HttpURLConnection) new URI(url).toURL().openConnection()
|
|
|
|
connection.requestMethod = "GET"
|
|
connection.connectTimeout = 5000
|
|
connection.readTimeout = 5000
|
|
|
|
connection.setRequestProperty("User-Agent", "LiquidBounce-App")
|
|
|
|
if (200 <= connection.responseCode && connection.responseCode <= 299) {
|
|
def response = connection.inputStream.text
|
|
def json = new JsonSlurper().parseText(response)
|
|
return json[]
|
|
.collect { it['author']['login'] }
|
|
.findAll { !(it as String).contains("dependabot") }
|
|
.reversed()
|
|
|
|
} else {
|
|
def error = connection.errorStream?.text ?: "No response details"
|
|
logger.log(LogLevel.ERROR, "Failed to collect contributors, github api responsed invalid status code: ${connection.responseCode}\n${error}")
|
|
return []
|
|
}
|
|
}
|
|
|
|
|
|
plugins {
|
|
id "fabric-loom"
|
|
id "org.jetbrains.kotlin.jvm"
|
|
id "com.gorylenko.gradle-git-properties" version "2.4.2"
|
|
id "io.gitlab.arturbosch.detekt" version "1.23.6"
|
|
id "com.github.node-gradle.node" version "7.1.0"
|
|
id "org.jetbrains.dokka" version "1.9.10"
|
|
}
|
|
|
|
base {
|
|
archivesBaseName = project.archives_base_name
|
|
version = project.mod_version
|
|
group = project.maven_group
|
|
}
|
|
|
|
configurations {
|
|
includeDependency
|
|
includeModDependency
|
|
|
|
include.extendsFrom includeModDependency
|
|
modImplementation.extendsFrom includeModDependency
|
|
modCompileOnlyApi.extendsFrom includeModDependency
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
mavenLocal()
|
|
maven { url = "https://maven.fabricmc.net/" }
|
|
maven {
|
|
name = "Jitpack"
|
|
url = "https://jitpack.io"
|
|
}
|
|
maven {
|
|
name = "TerraformersMC"
|
|
url = "https://maven.terraformersmc.com/"
|
|
}
|
|
maven {
|
|
name = "ViaVersion"
|
|
url = "https://repo.viaversion.com/"
|
|
}
|
|
maven {
|
|
name = "modrinth"
|
|
url = "https://api.modrinth.com/maven"
|
|
}
|
|
maven {
|
|
name = "OpenCollab Snapshots"
|
|
url = "https://repo.opencollab.dev/maven-snapshots/"
|
|
}
|
|
maven {
|
|
name = "Lenni0451"
|
|
url = "https://maven.lenni0451.net/everything"
|
|
}
|
|
}
|
|
|
|
loom {
|
|
accessWidenerPath = file("src/main/resources/liquidbounce.accesswidener")
|
|
}
|
|
|
|
dependencies {
|
|
// Minecraft
|
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
|
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
|
|
|
// Fabric
|
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
|
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"
|
|
|
|
// Recommended mods (on IDE)
|
|
modRuntimeOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
|
|
modImplementation "maven.modrinth:sodium:${project.sodium_version}"
|
|
modImplementation "maven.modrinth:lithium:${project.lithium_version}"
|
|
|
|
// ViaFabricPlus
|
|
modImplementation "com.viaversion:viafabricplus-api:${project.viafabricplus_version}"
|
|
modRuntimeOnly "com.viaversion:viafabricplus:${project.viafabricplus_version}"
|
|
|
|
// Minecraft Authlib
|
|
includeDependency ("com.github.CCBlueX:mc-authlib:${project.mc_authlib_version}") {
|
|
exclude group: "com.google.code.gson", module: "gson"
|
|
exclude group: "org.apache.logging.log4j", module: "log4j-core"
|
|
exclude group: "org.apache.logging.log4j", module: "log4j-api"
|
|
exclude group: "org.apache.logging.log4j", module: "log4j-slf4j-impl"
|
|
exclude group: "org.slf4j", module: "slf4j-api"
|
|
exclude group: "com.mojang", module: "authlib"
|
|
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib"
|
|
}
|
|
|
|
// JCEF Support
|
|
includeModDependency ("com.github.CCBlueX:mcef:${project.mcef_version}") {
|
|
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib"
|
|
}
|
|
includeDependency "org.apache.commons:commons-compress:1.27.1"
|
|
includeDependency ("com.github.CCBlueX:netty-httpserver:2.1.1") {
|
|
exclude group: "io.netty", module: "netty-all"
|
|
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib"
|
|
}
|
|
|
|
// Discord RPC Support
|
|
includeDependency "com.github.CCBlueX:DiscordIPC:4.0.0"
|
|
|
|
// ScriptAPI
|
|
includeDependency "net.fabricmc:tiny-mappings-parser:0.3.0+build.17"
|
|
includeDependency "org.graalvm.polyglot:polyglot:24.0.2"
|
|
includeDependency "org.graalvm.polyglot:js-community:24.0.2"
|
|
includeDependency "org.graalvm.polyglot:tools-community:24.0.2"
|
|
// includeDependency "org.graalvm.polyglot:python-community:24.0.2"
|
|
// includeDependency "org.graalvm.polyglot:wasm-community:24.0.2"
|
|
// includeDependency "org.graalvm.polyglot:java-community:24.0.2"
|
|
// includeDependency "org.graalvm.polyglot:ruby-community:24.0.2"
|
|
// includeDependency "org.graalvm.polyglot:llvm-native-community:24.0.2"
|
|
|
|
// HTTP library
|
|
includeDependency ("com.squareup.okhttp3:okhttp:5.0.0-alpha.14") {
|
|
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib"
|
|
}
|
|
|
|
// SOCKS5 Proxy Support
|
|
includeDependency ("io.netty:netty-handler-proxy:4.1.97.Final") {
|
|
exclude group: "io.netty", module: "netty-common"
|
|
exclude group: "io.netty", module: "netty-buffer"
|
|
exclude group: "io.netty", module: "netty-transport"
|
|
exclude group: "io.netty", module: "netty-codec"
|
|
}
|
|
|
|
// Update Checker
|
|
includeDependency "com.vdurmont:semver4j:3.1.0"
|
|
|
|
// Name Protect
|
|
includeDependency "org.ahocorasick:ahocorasick:0.6.3"
|
|
|
|
// Test libraries
|
|
testImplementation "org.junit.jupiter:junit-jupiter:5.11.3"
|
|
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
|
|
|
|
// Fix nullable annotations
|
|
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
|
|
|
|
afterEvaluate {
|
|
configurations.includeDependency.incoming.resolutionResult.allDependencies.each {
|
|
dependencies.include(dependencies.implementation(dependencies.compileOnlyApi(it.requested.toString()) {
|
|
transitive = false
|
|
}))
|
|
}
|
|
}
|
|
testImplementation "org.jetbrains.kotlin:kotlin-test:2.1.0"
|
|
}
|
|
|
|
processResources {
|
|
String contributors = JsonOutput.prettyPrint(JsonOutput.toJson(getContributors("CCBlueX", "LiquidBounce")))
|
|
|
|
inputs.property "version", project.version
|
|
|
|
inputs.property "minecraft_version", minecraft_version
|
|
inputs.property "fabric_version", fabric_version
|
|
inputs.property "loader_version", loader_version
|
|
inputs.property "min_loader_version", min_loader_version
|
|
inputs.property "fabric_kotlin_version", fabric_kotlin_version
|
|
inputs.property "viafabricplus_version", viafabricplus_version
|
|
inputs.property "contributors", contributors
|
|
|
|
filesMatching("fabric.mod.json") {
|
|
expand([
|
|
version : project.version,
|
|
minecraft_version : minecraft_version,
|
|
fabric_version : fabric_version,
|
|
loader_version : loader_version,
|
|
min_loader_version : min_loader_version,
|
|
contributors : contributors,
|
|
fabric_kotlin_version: fabric_kotlin_version,
|
|
viafabricplus_version: viafabricplus_version
|
|
])
|
|
}
|
|
}
|
|
|
|
// The following code will include the theme into the build
|
|
|
|
tasks.register("npmInstallTheme", NpmTask) {
|
|
workingDir = file("src-theme")
|
|
args = ["i"]
|
|
doLast {
|
|
println "Successfully installed dependencies for theme"
|
|
}
|
|
|
|
inputs.files("src-theme/package.json", "src-theme/package-lock.json")
|
|
outputs.dir("src-theme/node_modules")
|
|
}
|
|
|
|
tasks.register("buildTheme", NpmTask) {
|
|
dependsOn "npmInstallTheme"
|
|
workingDir = file("src-theme")
|
|
args = ["run", "build"]
|
|
doLast {
|
|
println "Successfully build theme"
|
|
}
|
|
|
|
inputs.files(
|
|
"src-theme/package.json",
|
|
"src-theme/package-lock.json",
|
|
"src-theme/bundle.cjs",
|
|
"src-theme/rollup.config.js"
|
|
)
|
|
inputs.dir("src-theme/src")
|
|
outputs.dir("src-theme/dist")
|
|
}
|
|
|
|
tasks.register("bundleTheme", NodeTask) {
|
|
dependsOn "buildTheme"
|
|
workingDir = file("src-theme")
|
|
script = file("src-theme/bundle.cjs")
|
|
doLast {
|
|
println "Successfully attached theme to build"
|
|
}
|
|
|
|
// Incremental stuff
|
|
inputs.files(
|
|
"src-theme/package.json",
|
|
"src-theme/package-lock.json",
|
|
"src-theme/bundle.cjs",
|
|
"src-theme/rollup.config.js"
|
|
)
|
|
inputs.dir("src-theme/src")
|
|
inputs.dir("src-theme/public")
|
|
inputs.dir("src-theme/dist")
|
|
outputs.files("src-theme/resources/assets/liquidbounce/default_theme.zip")
|
|
}
|
|
|
|
sourceSets {
|
|
main {
|
|
resources {
|
|
srcDirs "src-theme/resources"
|
|
}
|
|
}
|
|
}
|
|
|
|
processResources.dependsOn bundleTheme
|
|
|
|
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
|
// this fixes some edge cases with special characters not displaying correctly
|
|
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
|
tasks.withType(JavaCompile).configureEach {
|
|
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
|
// this fixes some edge cases with special characters not displaying correctly
|
|
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
|
// If Javadoc is generated, this must be specified in that task too.
|
|
it.options.encoding = "UTF-8"
|
|
|
|
// Minecraft 1.20.5 upwards uses Java 17.
|
|
it.options.release = 21
|
|
}
|
|
|
|
tasks.withType(Test).configureEach {
|
|
useJUnitPlatform()
|
|
dependsOn(tasks.named("genSources"))
|
|
}
|
|
|
|
detekt {
|
|
config.setFrom(file("${rootProject.projectDir}/config/detekt/detekt.yml"))
|
|
buildUponDefaultConfig = true
|
|
baseline = file("${rootProject.projectDir}/config/detekt/baseline.xml")
|
|
}
|
|
|
|
task detektProjectBaseline(type: io.gitlab.arturbosch.detekt.DetektCreateBaselineTask) {
|
|
description = "Overrides current baseline."
|
|
ignoreFailures.set(true)
|
|
parallel.set(true)
|
|
buildUponDefaultConfig.set(true)
|
|
setSource(files(rootDir))
|
|
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
|
|
baseline.set(file("$rootDir/config/detekt/baseline.xml"))
|
|
include("**/*.kt")
|
|
include("**/*.kts")
|
|
exclude("**/resources/**")
|
|
exclude("**/build/**")
|
|
}
|
|
|
|
tasks.register("verifyI18nJsonKeys") {
|
|
def baselineFileName = "en_us.json"
|
|
|
|
group = "verification"
|
|
description = "Compare i18n JSON files with ${baselineFileName} as the baseline and report missing keys."
|
|
|
|
def i18nDir = file("src/main/resources/resources/liquidbounce/lang")
|
|
|
|
doLast {
|
|
if (!i18nDir.exists() || !i18nDir.isDirectory()) {
|
|
throw new GradleException("The specified directory ${i18nDir} does not exist or is not a directory.")
|
|
}
|
|
|
|
def baselineFile = new File(i18nDir, baselineFileName)
|
|
if (!baselineFile.exists()) {
|
|
throw new GradleException("Baseline file ${baselineFileName} not found in ${i18nDir}.")
|
|
}
|
|
|
|
def baseline = new JsonSlurper().parse(baselineFile)
|
|
|
|
i18nDir.eachFile { file ->
|
|
if (file.name.endsWith(".json") && file.name != baselineFileName) {
|
|
def currentFile = new JsonSlurper().parse(file)
|
|
|
|
def missingKeys = baseline.keySet() - currentFile.keySet()
|
|
|
|
if (missingKeys.isEmpty()) {
|
|
println "${file.name} is complete. No missing keys."
|
|
} else {
|
|
def limitedMissingKeys = missingKeys.take(5)
|
|
def output = limitedMissingKeys.join(', ')
|
|
if (missingKeys.size() > 5) {
|
|
output += ", ..."
|
|
}
|
|
println "${file.name} is missing the following keys (${missingKeys.size()}): ${output}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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_21
|
|
targetCompatibility = JavaVersion.VERSION_21
|
|
}
|
|
|
|
compileKotlin {
|
|
compilerOptions {
|
|
suppressWarnings = true
|
|
jvmTarget = JvmTarget.JVM_21
|
|
}
|
|
}
|
|
|
|
jar {
|
|
// Rename the project"s license file to LICENSE_<project_name> to avoid conflicts
|
|
from("LICENSE") {
|
|
rename {
|
|
"${it}_${project.archives_base_name}"
|
|
}
|
|
}
|
|
|
|
from(configurations.mappings.collect { zipTree(it) }) {
|
|
include "mappings/mappings.tiny"
|
|
}
|
|
}
|
|
|
|
tasks.register("copyZipInclude", Copy) {
|
|
from "zip_include/"
|
|
into "build/libs/zip"
|
|
}
|
|
|
|
sourcesJar.dependsOn bundleTheme
|
|
build.dependsOn copyZipInclude
|
|
|
|
tasks.named("compileJava").configure { dependsOn("genSources") }
|