Skip to content

Commit

Permalink
feat: gradle file size reduced
Browse files Browse the repository at this point in the history
  • Loading branch information
Nopock committed Nov 7, 2023
1 parent 073e8ab commit 54d8b47
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 118 deletions.
103 changes: 54 additions & 49 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import org.jetbrains.gradle.ext.runConfigurations
import org.jetbrains.gradle.ext.settings

plugins {
kotlin("jvm") version "1.9.10"
kotlin("kapt") version "1.9.10"
id("maven-publish")
id("io.sentry.jvm.gradle") version "3.12.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
kotlin("jvm") version "1.9.10"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"
id("org.jetbrains.dokka") version "1.9.0"
kotlin("kapt") version "1.9.10"
id("com.google.protobuf") version "0.9.4" apply false
}

Expand All @@ -39,7 +39,6 @@ allprojects {
apply(plugin = "maven-publish")
apply(plugin = "kotlin")
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "org.jetbrains.gradle.plugin.idea-ext")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "org.jetbrains.kotlin.kapt")
Expand All @@ -53,11 +52,59 @@ allprojects {
maven("https://jitpack.io")
}

dependencies {
testImplementation(kotlin("test"))
fun applyGlobalDepends(scope: DependencyHandlerScope, shade: Boolean = false) {
scope {
if (!shade) {
compileOnly(kotlin("stdlib"))
compileOnly(kotlin("reflect")) // Add this line

compileOnly("org.mongodb:mongo-java-driver:3.12.11")
compileOnly("io.lettuce:lettuce-core:6.2.4.RELEASE")
compileOnly("io.sentry:sentry:6.29.0")
compileOnly("com.konghq:unirest-java:3.13.6:standalone")

// Docker
compileOnly("com.github.docker-java:docker-java:3.3.4")

// Cloudflare
compileOnly("com.github.robinbraemer:CloudflareAPI:1.4.1")

compileOnly("com.google.guava:guava:31.0.1-jre")
compileOnly("commons-io:commons-io:2.11.0")
} else {
implementation(kotlin("stdlib"))
implementation(kotlin("reflect")) // Add this line

implementation("org.mongodb:mongo-java-driver:3.12.11")
implementation("io.lettuce:lettuce-core:6.2.4.RELEASE")
implementation("com.google.code.gson:gson:2.9.0")
implementation("io.sentry:sentry:6.29.0")
implementation("com.konghq:unirest-java:3.13.6:standalone")

// Docker
implementation("com.github.docker-java:docker-java:3.3.4")

// Cloudflare
implementation("com.github.robinbraemer:CloudflareAPI:1.4.1")

implementation("com.google.guava:guava:31.0.1-jre")
implementation("commons-io:commons-io:2.11.0")
}
}
}

dependencies {
// Generate documentation
dokkaPlugin("org.jetbrains.dokka:versioning-plugin:1.9.0")

if (name.contains("api") || name.contains("protocol") || name.contains("minecraft-platform") || name == "paper-core") {
applyGlobalDepends(this)
} else if ((name.contains("core") && !name.contains("paper") && !name.contains("nms")) || name.contains("backend")) {
applyGlobalDepends(this, true)
} else {
compileOnly(kotlin("stdlib"))
compileOnly(kotlin("reflect")) // Add this line
}
}

tasks.withType<ShadowJar> {
Expand All @@ -82,50 +129,6 @@ allprojects {
}
}

configurations.create("final") {
dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("reflect")) // Add this line

implementation("org.mongodb:mongo-java-driver:3.12.11")
implementation("io.lettuce:lettuce-core:6.2.4.RELEASE")
implementation("com.google.code.gson:gson:2.9.0")
implementation("io.sentry:sentry:6.29.0")
implementation("com.konghq:unirest-java:3.13.6:standalone")

// Docker
implementation("com.github.docker-java:docker-java:3.3.4")

// Cloudflare
implementation("com.github.robinbraemer:CloudflareAPI:1.4.1")

implementation("com.google.guava:guava:31.0.1-jre")
implementation("commons-io:commons-io:2.11.0")
}
}

configurations.create("non-final") {
dependencies {
compileOnly(kotlin("stdlib"))
compileOnly(kotlin("reflect")) // Add this line

compileOnly("org.mongodb:mongo-java-driver:3.12.11")
compileOnly("io.lettuce:lettuce-core:6.2.4.RELEASE")
compileOnly("com.google.code.gson:gson:2.9.0")
compileOnly("io.sentry:sentry:6.29.0")
compileOnly("com.konghq:unirest-java:3.13.6:standalone")

// Docker
compileOnly("com.github.docker-java:docker-java:3.3.4")

// Cloudflare
compileOnly("com.github.robinbraemer:CloudflareAPI:1.4.1")

compileOnly("com.google.guava:guava:31.0.1-jre")
compileOnly("commons-io:commons-io:2.11.0")
}
}

publishing {
publications {
register(
Expand Down Expand Up @@ -161,6 +164,8 @@ allprojects {
tasks.processResources {
duplicatesStrategy = DuplicatesStrategy.WARN // or DuplicatesStrategy.FAIL
}

tasks["build"].dependsOn("shadowJar")
}

kotlin {
Expand Down
16 changes: 6 additions & 10 deletions independent/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
dependencies {
api("org.reflections:reflections:0.10.2")
api("com.github.ben-manes.caffeine:caffeine:3.1.8")
api("com.squareup.retrofit2:retrofit:2.9.0")
api("com.squareup.retrofit2:converter-gson:2.9.0")
api("co.aikar:acf-core:0.5.1-SNAPSHOT")
api("de.mkammerer:argon2-jvm:2.11")

configurations.getByName("non-final").dependencies.forEach {
this.compileOnly(it)
}
compileOnly("org.reflections:reflections:0.10.2")
compileOnly("com.github.ben-manes.caffeine:caffeine:3.1.8")
compileOnly("com.squareup.retrofit2:retrofit:2.9.0")
compileOnly("com.squareup.retrofit2:converter-gson:2.9.0")
compileOnly("co.aikar:acf-core:0.5.1-SNAPSHOT")
compileOnly("de.mkammerer:argon2-jvm:2.11")
}
2 changes: 0 additions & 2 deletions independent/backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ dependencies {

implementation("com.squareup.retrofit2:retrofit:2.9.0")
}

tasks["build"].dependsOn("shadowJar")
4 changes: 1 addition & 3 deletions independent/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@ dependencies {
implementation("io.kubernetes:client-java:15.0.1")

implementation("com.squareup.retrofit2:retrofit:2.9.0")
}

tasks["build"].dependsOn("shadowJar")
}
12 changes: 6 additions & 6 deletions independent/protocol-stub/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ plugins {
dependencies {
protobuf(project(":independent:protocol"))

api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${rootProject.ext["coroutinesVersion"]}")
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:${rootProject.ext["coroutinesVersion"]}")

api("io.grpc:grpc-stub:${rootProject.ext["grpcVersion"]}")
api("io.grpc:grpc-protobuf:${rootProject.ext["grpcVersion"]}")
api("com.google.protobuf:protobuf-java-util:${rootProject.ext["protobufVersion"]}")
api("com.google.protobuf:protobuf-kotlin:${rootProject.ext["protobufVersion"]}")
api("io.grpc:grpc-kotlin-stub:${rootProject.ext["grpcKotlinVersion"]}")
compileOnly("io.grpc:grpc-stub:${rootProject.ext["grpcVersion"]}")
compileOnly("io.grpc:grpc-protobuf:${rootProject.ext["grpcVersion"]}")
compileOnly("com.google.protobuf:protobuf-java-util:${rootProject.ext["protobufVersion"]}")
compileOnly("com.google.protobuf:protobuf-kotlin:${rootProject.ext["protobufVersion"]}")
compileOnly("io.grpc:grpc-kotlin-stub:${rootProject.ext["grpcKotlinVersion"]}")
}


Expand Down
20 changes: 10 additions & 10 deletions mc-commons/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
dependencies {
api("net.kyori:adventure-api:4.14.0")
api("net.kyori:adventure-key:4.14.0")
api("net.kyori:adventure-text-minimessage:4.10.1")
compileOnly("net.kyori:adventure-api:4.14.0")
compileOnly("net.kyori:adventure-key:4.14.0")
compileOnly("net.kyori:adventure-text-minimessage:4.10.1")

api("co.aikar:acf-core:0.5.1-SNAPSHOT")
api(project(":independent:independent-api"))
compileOnly("co.aikar:acf-core:0.5.1-SNAPSHOT")
compileOnly(project(":independent:independent-api"))

api("io.grpc:grpc-netty:${rootProject.ext["grpcVersion"]}")
api(project(":independent:protocol-stub"))
api("io.grpc:grpc-protobuf:${rootProject.ext["grpcVersion"]}")
api("api.google.protobuf:protobuf-java-util:${rootProject.ext["protobufVersion"]}")
api("io.grpc:grpc-kotlin-stub:${rootProject.ext["grpcKotlinVersion"]}")
compileOnly("io.grpc:grpc-netty:${rootProject.ext["grpcVersion"]}")
compileOnly(project(":independent:protocol-stub"))
compileOnly("io.grpc:grpc-protobuf:${rootProject.ext["grpcVersion"]}")
compileOnly("com.google.protobuf:protobuf-java-util:${rootProject.ext["protobufVersion"]}")
compileOnly("io.grpc:grpc-kotlin-stub:${rootProject.ext["grpcKotlinVersion"]}")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package net.revive.framework.maven

import com.google.common.base.Supplier
import com.google.common.base.Suppliers
import net.revive.framework.Framework
import net.revive.framework.flavor.annotation.Inject
import net.revive.framework.flavor.service.Service
import net.revive.framework.server.IMinecraftPlatform
import java.io.File
import java.net.MalformedURLException
import java.net.URL
Expand All @@ -18,16 +14,9 @@ import java.util.*
* Resolves [MavenLibrary] annotations for a class, and loads the dependency
* into the classloader.
*/
@Service
object MavenLibraryLoader {
private val URL_INJECTOR: Supplier<URLClassLoaderAccess> = Suppliers.memoize {
URLClassLoaderAccess.create(
IMinecraftPlatform::class.java.getClassLoader() as URLClassLoader
)
}

@Inject
lateinit var minecraftPlatform: IMinecraftPlatform
lateinit var URL_INJECTOR: Supplier<URLClassLoaderAccess>

/**
* Resolves all [MavenLibrary] annotations on the given object.
Expand All @@ -44,6 +33,12 @@ object MavenLibraryLoader {
* @param clazz the class to load libraries for.
*/
fun loadAll(clazz: Class<*>) {
URL_INJECTOR = Suppliers.memoize {
URLClassLoaderAccess.create(
clazz.getClassLoader() as URLClassLoader
)
}

val libs: Array<MavenLibrary> = clazz.getDeclaredAnnotationsByType(MavenLibrary::class.java) ?: return
for (lib in libs) {
load(lib.groupId, lib.artifactId, lib.version, lib.repo.url)
Expand Down
18 changes: 11 additions & 7 deletions paper/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ repositories {
}

dependencies {
// all of our stuff
implementation(project(":paper"))
implementation(project(":independent:independent-api"))
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("net.wesjd:anvilgui:1.9.0-SNAPSHOT")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
implementation("fr.mrmicky:fastboard:2.0.0")
implementation(project(":minecraft-platform"))

implementation("me.lucko:helper:5.6.10")

compileOnly("com.squareup.retrofit2:retrofit:2.9.0")
compileOnly("net.wesjd:anvilgui:1.9.0-SNAPSHOT")
compileOnly("com.squareup.retrofit2:converter-gson:2.9.0")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("co.aikar:acf-paper:0.5.1-SNAPSHOT")
compileOnly("fr.mrmicky:fastboard:2.0.0")
compileOnly("me.lucko:helper:5.6.10")
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
implementation(project(":minecraft-platform"))

compileOnly(project(":paper:nms:nms-core"))
compileOnly("com.github.cryptomorin:XSeries:9.5.0") { isTransitive = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ open class ExtendedKotlinPlugin : ExtendedJavaPlugin(), IConfigProvider {
Bukkit.shutdown()
return
}

MavenLibraryLoader.loadAll(this::class.java)

this.flavor =
Flavor.create((Bukkit.getPluginManager().getPlugin(description.name) ?: this)::class, FlavorOptions(logger))
this.flavor.reflections = PackageIndexer(this::class, FlavorOptions(logger), listOf(this.classLoader))
Expand Down
9 changes: 0 additions & 9 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
repositories {

maven("https://maven.enginehub.org/repo/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
}
dependencies {
implementation("com.squareup.retrofit:retrofit:2.0.0-beta2")
}
7 changes: 4 additions & 3 deletions paper/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ repositories {

dependencies {
// local project includes
implementation(kotlin("stdlib"))
implementation(kotlin("reflect")) // Add this line

implementation(project(":independent:independent-api"))

implementation(project(":paper:paper-api"))
Expand All @@ -25,7 +28,7 @@ dependencies {
compileOnly("net.luckperms:api:5.4")
compileOnly("net.kyori:adventure-platform-bukkit:4.1.0")

compileOnly("co.aikar:acf-paper:0.5.1-SNAPSHOT")
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
// final compilation libraries
implementation("net.wesjd:anvilgui:1.9.0-SNAPSHOT")
compileOnly("net.kyori:adventure-text-serializer-gson:4.10.1")
Expand All @@ -52,5 +55,3 @@ dependencies {
compileOnly("com.google.protobuf:protobuf-java-util:${rootProject.ext["protobufVersion"]}")
compileOnly("io.grpc:grpc-kotlin-stub:${rootProject.ext["grpcKotlinVersion"]}")
}

tasks["build"].dependsOn("shadowJar")
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ import java.util.concurrent.TimeUnit
]
)
@HelperImplementationPlugin
@MavenLibrary(
"javassist",
"javassist",
"3.12.1.GA"
)
@MavenLibrary(
"net.kyori",
"adventure-text-serializer-gson",
Expand Down
3 changes: 3 additions & 0 deletions paper/nms/v1_12_R2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {

}
3 changes: 3 additions & 0 deletions paper/nms/v1_8_R8/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {

}
12 changes: 6 additions & 6 deletions velocity/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
dependencies {
api(project(":independent:independent-api"))
compileOnly(project(":independent:independent-api"))

api("com.squareup.retrofit2:retrofit:2.9.0")
api("com.squareup.retrofit2:converter-gson:2.9.0")
api("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
compileOnly("com.squareup.retrofit2:retrofit:2.9.0")
compileOnly("com.squareup.retrofit2:converter-gson:2.9.0")
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")

api("co.aikar:acf-core:0.5.1-SNAPSHOT")
compileOnly("co.aikar:acf-core:0.5.1-SNAPSHOT")

configurations.getByName("non-final")
//configurations.getByName("non-final")
}
2 changes: 1 addition & 1 deletion velocity/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ dependencies {
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")

configurations.getByName("final")
//configurations.getByName("final")
}

0 comments on commit 54d8b47

Please sign in to comment.