Skip to content

Commit

Permalink
feat: Reduced jar file size by downloading geoip2 at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed May 12, 2023
1 parent 8f3a209 commit c0a9049
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 39 deletions.
3 changes: 0 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ subprojects {
val platformName = project.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
archiveFileName.set("EpicGuard$platformName-${project.version}.jar")

relocate("com.fasterxml", "me.xneox.epicguard.libs.fasterxml")
relocate("com.maxmind", "me.xneox.epicguard.libs.maxmind")

minimize()

// Copy compiled platform jars to '/build' directory for convenience.
Expand Down
6 changes: 4 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

dependencies {
implementation(libs.geoip)
compileOnly(libs.geoip)
compileOnly(libs.commons.compress)
compileOnly(libs.commons.text)
compileOnly(libs.guava)
Expand Down Expand Up @@ -41,7 +41,9 @@ blossom {
replaceToken("{caffeine}", libs.versions.caffeine.get())
replaceToken("{common-compress}", libs.versions.commons.compress.get())
replaceToken("{common-text}", libs.versions.commons.text.get())

replaceToken("{geoip}", libs.versions.geoip.get())
replaceToken("{jackson}", libs.versions.jackson.get())
replaceToken("{maxmind-db}", libs.versions.maxmind.db.get())
}

// Publish to Maven Central
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public final class VersionUtils {
public static final String CAFFEINE = "{caffeine}";
public static final String COMMONS_TEXT = "{common-text}";
public static final String COMMANDS_COMPRESS = "{common-compress}";
public static final String GEOIP = "{geoip}";
public static final String JACKSON = "{jackson}";
public static final String MAXMIND_DB = "{maxmind-db}";
private static final String CHECK_URL = "https://raw.githubusercontent.com/4drian3d/EpicGuard/master/VERSION.txt";

private static boolean updateAvailable;
Expand Down
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ commons-compress = "1.23.0"
commons-text = "1.10.0"

geoip = "4.0.1"
jackson = "2.14.2"
maxmind-db = "3.0.0"

caffeine = "3.1.6"

Expand Down Expand Up @@ -73,6 +75,10 @@ commons-text = { group = "org.apache.commons", name = "commons-text", version.re
commons-compress = { group = "org.apache.commons", name = "commons-compress", version.ref = "commons-compress" }

geoip = { group = "com.maxmind.geoip2", name = "geoip2", version.ref = "geoip" }
maxmind-db = { group = "com.maxmind.db", name = "maxmind-db", version.ref = "maxmind-db" }
jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" }
jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }

caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version.ref = "caffeine" }

Expand Down
43 changes: 17 additions & 26 deletions paper/src/main/java/me/xneox/epicguard/paper/LibraryLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.eclipse.aether.repository.RemoteRepository;
import org.jetbrains.annotations.NotNull;

import java.util.stream.Stream;

@SuppressWarnings({"unused", "UnstableApiUsage"})
public class LibraryLoader implements PluginLoader {
@Override
Expand All @@ -18,33 +20,22 @@ public void classloader(@NotNull PluginClasspathBuilder classpathBuilder) {
final RemoteRepository mavenCentral = new RemoteRepository
.Builder("central", "default", "https://repo1.maven.org/maven2/")
.build();
final Dependency configurateHocon = new Dependency(
new DefaultArtifact("org.spongepowered:configurate-hocon:"+VersionUtils.CONFIGURATE),
null
);
final Dependency hikari = new Dependency(
new DefaultArtifact("com.zaxxer:HikariCP:"+ VersionUtils.HIKARI),
null
);
final Dependency caffeine = new Dependency(
new DefaultArtifact("com.github.ben-manes.caffeine:caffeine:"+ VersionUtils.CAFFEINE),
null
);
final Dependency compress = new Dependency(
new DefaultArtifact("org.apache.commons:commons-compress:"+ VersionUtils.COMMANDS_COMPRESS),
null
);
final Dependency text = new Dependency(
new DefaultArtifact("org.apache.commons:commons-text:"+ VersionUtils.COMMONS_TEXT),
null
);

resolver.addRepository(mavenCentral);
resolver.addDependency(configurateHocon);
resolver.addDependency(hikari);
resolver.addDependency(caffeine);
resolver.addDependency(compress);
resolver.addDependency(text);

Stream.of(
"org.spongepowered:configurate-hocon:" + VersionUtils.CONFIGURATE,
"com.zaxxer:HikariCP:" + VersionUtils.HIKARI,
"com.github.ben-manes.caffeine:caffeine:" + VersionUtils.CAFFEINE,
"org.apache.commons:commons-compress:" + VersionUtils.COMMANDS_COMPRESS,
"org.apache.commons:commons-text:" + VersionUtils.COMMONS_TEXT,
"com.maxmind.geoip2:geoip2:" + VersionUtils.GEOIP,
"com.maxmind.db:maxmind-db:" + VersionUtils.MAXMIND_DB,
"com.fasterxml.jackson.core:jackson-annotations:" + VersionUtils.JACKSON,
"com.fasterxml.jackson.core:jackson-core:" + VersionUtils.JACKSON,
"com.fasterxml.jackson.core:jackson-databind:" + VersionUtils.JACKSON
)
.map(artifact -> new Dependency(new DefaultArtifact(artifact), null))
.forEach(resolver::addDependency);

classpathBuilder.addLibrary(resolver);
}
Expand Down
35 changes: 35 additions & 0 deletions velocity/src/main/java/me/xneox/epicguard/velocity/Libraries.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,36 @@ void register() {
.id("commons-text")
.relocate(commonsRelocation)
.build();
final Library MAXMIND_GEOIP = Library.builder()
.groupId("com.maxmind.geoip2")
.artifactId("geoip2")
.version(VersionUtils.GEOIP)
.id("geoip2")
.build();
final Library MAXMIND_DB = Library.builder()
.groupId("com.maxmind.db")
.artifactId("maxmind-db")
.version(VersionUtils.MAXMIND_DB)
.id("maxmind-db")
.build();
final Library JACKSON_ANNOTATIONS = Library.builder()
.groupId("com.fasterxml.jackson.core")
.artifactId("jackson-annotations")
.version(VersionUtils.JACKSON)
.id("jackson-annotations")
.build();
final Library JACKSON_CORE = Library.builder()
.groupId("com.fasterxml.jackson.core")
.artifactId("jackson-core")
.version(VersionUtils.JACKSON)
.id("jackson-core")
.build();
final Library JACKSON_DATABIND = Library.builder()
.groupId("com.fasterxml.jackson.core")
.artifactId("jackson-databind")
.version(VersionUtils.JACKSON)
.id("jackson-databind")
.build();

manager.addMavenCentral();
manager.loadLibrary(SQLITE);
Expand All @@ -107,6 +137,11 @@ void register() {
manager.loadLibrary(HIKARI);
manager.loadLibrary(COMMONS_COMPRESS);
manager.loadLibrary(COMMONS_TEXT);
manager.loadLibrary(MAXMIND_GEOIP);
manager.loadLibrary(MAXMIND_DB);
manager.loadLibrary(JACKSON_ANNOTATIONS);
manager.loadLibrary(JACKSON_CORE);
manager.loadLibrary(JACKSON_DATABIND);
}

}
22 changes: 14 additions & 8 deletions waterfall/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ bungee {
version = project.version as String
author = "neox, 4drian3d"
libraries = listOf(
"${libs.adventure.platform.bungeecord.get().module}:${libs.versions.adventure.platform.get()}",
"${libs.sqlite.get().module}:${libs.versions.sqlite.get()}",
"${libs.caffeine.get().module}:${libs.versions.caffeine.get()}",
"${libs.hikaricp.get().module}:${libs.versions.hikaricp.get()}",
"${libs.configurate.get().module}:${libs.versions.configurate.get()}",
"${libs.commons.compress.get().module}:${libs.versions.commons.compress.get()}",
"${libs.commons.text.get().module}:${libs.versions.commons.text.get()}",
)
libs.adventure.platform.bungeecord to libs.versions.adventure.platform,
libs.sqlite to libs.versions.sqlite,
libs.caffeine to libs.versions.caffeine,
libs.hikaricp to libs.versions.hikaricp,
libs.configurate to libs.versions.configurate,
libs.commons.compress to libs.versions.commons.compress,
libs.commons.text to libs.versions.commons.text,
libs.geoip to libs.versions.geoip,
libs.maxmind.db to libs.versions.maxmind.db,
libs.jackson.core to libs.versions.jackson,
libs.jackson.databind to libs.versions.jackson,
libs.jackson.annotations to libs.versions.jackson,
).map { "${it.first.get().module}:${it.second.get()}" }
}

0 comments on commit c0a9049

Please sign in to comment.