Skip to content

Commit

Permalink
more gradle clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
vectrixdevelops committed Sep 22, 2023
1 parent d0d024e commit 188de47
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 106 deletions.
95 changes: 12 additions & 83 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,28 @@ plugins {
id("apollo.publish-conventions")
}

val bukkitConfig = configurations.register("bukkit")
val bungeeConfig = configurations.register("bungee")
val velocityConfig = configurations.register("velocity")
setupPlatforms()

val main by sourceSets

val bukkitSource by sourceSets.register("bukkit") {
project.dependencies.add(this.implementationConfigurationName, main.output)

compileClasspath += main.compileClasspath
compileClasspath += main.runtimeClasspath

configurations.named(implementationConfigurationName) {
extendsFrom(bukkitConfig.get())
}
}

val bungeeSource by sourceSets.register("bungee") {
project.dependencies.add(this.implementationConfigurationName, main.output)

compileClasspath += main.compileClasspath
compileClasspath += main.runtimeClasspath

configurations.named(implementationConfigurationName) {
extendsFrom(bungeeConfig.get())
}
}

val velocitySource by sourceSets.register("velocity") {
project.dependencies.add(this.implementationConfigurationName, main.output)

compileClasspath += main.compileClasspath
compileClasspath += main.runtimeClasspath
setupPlatformDependency("bukkit", "bukkitJar")
setupPlatformDependency("bungee", "bungeeJar")
setupPlatformDependency("velocity", "velocityJar")

configurations.named(implementationConfigurationName) {
extendsFrom(velocityConfig.get())
}
}
val main by sourceSets

dependencies {
api(project(":extra:apollo-extra-adventure4"))

api(libs.geantyref)

val bukkit = bukkitConfig.name
bukkit(main.output)
bukkit(libs.bukkit.api)
bukkit(libs.bukkit)

val bungee = bungeeConfig.name
bungee(main.output)
bungee(libs.bungee)

val velocity = velocityConfig.name
velocity(main.output)
velocity(libs.velocity)
}

tasks {
val bukkitJar by registering(Jar::class) {
archiveClassifier.set("bukkit")
from(bukkitSource.output)
}
"bukkit"(main.output)
"bukkit"(libs.bukkit.api)
"bukkit"(libs.bukkit)

val bungeeJar by registering(Jar::class) {
archiveClassifier.set("bungee")
from(bungeeSource.output)
}

val velocityJar by registering(Jar::class) {
archiveClassifier.set("velocity")
from(velocitySource.output)
}

shadowJar {
configurations = listOf()

from(jar)
from(bukkitJar)
from(bungeeJar)
from(velocityJar)
}

javadoc {
source(sourceSets.map { it.allJava })
classpath += sourceSets.map { it.compileClasspath }.reduce { first, second -> first + second }
}
}
"bungee"(main.output)
"bungee"(libs.bungee)

artifacts {
add("bukkit", tasks["bukkitJar"])
add("bungee", tasks["bungeeJar"])
add("velocity", tasks["velocityJar"])
"velocity"(main.output)
"velocity"(libs.velocity)
}

publishShadowJar()
52 changes: 51 additions & 1 deletion build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.*

Expand All @@ -20,6 +21,55 @@ fun ShadowJar.configureExclusions() {
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
}

fun Project.setupPlatforms() {
extensions.configure<JavaPluginExtension> {
val jar by tasks.named("jar")

val shadowJar by tasks.named("shadowJar", ShadowJar::class) {
configurations = listOf()

from(jar)
}

tasks.named("javadoc", Javadoc::class) {
source(sourceSets.map { it.allJava })
classpath += sourceSets.map { it.compileClasspath }.reduce { first, second -> first + second }
}
}
}

fun Project.setupPlatformDependency(configurationName: String, jarTaskName: String) {
extensions.configure<JavaPluginExtension> {
val configuration = configurations.register(configurationName)

val main by sourceSets

val source by sourceSets.register(configurationName) {
project.dependencies.add(this.implementationConfigurationName, main.output)

compileClasspath += main.compileClasspath
compileClasspath += main.runtimeClasspath

configurations.named(this.implementationConfigurationName) {
extendsFrom(configuration.get())
}
}

val jarTask by tasks.register(jarTaskName, Jar::class) {
archiveClassifier.set(configurationName)
from(source.output)
}

tasks.named("shadowJar", ShadowJar::class) {
from(jarTask)
}

artifacts {
add(configurationName, jarTask)
}
}
}

fun Project.setupDynamicLoader() {
extensions.configure<JavaPluginExtension> {
val loaderCompileOnlyConfig = configurations.register("loaderCompileOnly")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.lunarclient.apollo.option.OptionsImpl;
import java.util.logging.Logger;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
Expand All @@ -78,6 +79,7 @@
*
* @since 1.0.0
*/
@RequiredArgsConstructor
public final class ApolloBukkitPlatform implements PlatformPlugin, ApolloPlatform {

@Getter private static ApolloBukkitPlatform instance;
Expand All @@ -86,16 +88,6 @@ public final class ApolloBukkitPlatform implements PlatformPlugin, ApolloPlatfor

@Getter private final JavaPlugin plugin;

/**
* Constructs a new {@link ApolloBukkitPlatform}.
*
* @param plugin the plugin instance
* @since 1.0.0
*/
public ApolloBukkitPlatform(JavaPlugin plugin) {
this.plugin = plugin;
}

@Override
public void onEnable() {
ApolloBukkitPlatform.instance = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.lunarclient.apollo.option.OptionsImpl;
import java.util.logging.Logger;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;

Expand All @@ -38,6 +39,7 @@
*
* @since 1.0.0
*/
@RequiredArgsConstructor
public final class ApolloBungeePlatform implements PlatformPlugin, ApolloPlatform {

@Getter private static ApolloBungeePlatform instance;
Expand All @@ -46,16 +48,6 @@ public final class ApolloBungeePlatform implements PlatformPlugin, ApolloPlatfor

@Getter private final Plugin plugin;

/**
* Constructs a new {@link ApolloBungeePlatform}.
*
* @param plugin the plugin instance
* @since 1.0.0
*/
public ApolloBungeePlatform(Plugin plugin) {
this.plugin = plugin;
}

@Override
public void onEnable() {
ApolloBungeePlatform.instance = this;
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pluginManagement {
}
}

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
Expand Down

1 comment on commit 188de47

@LunarClientBot
Copy link
Collaborator

@LunarClientBot LunarClientBot commented on 188de47 Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📄 Documentation Deployment

Status:✅ Completed
Environment:preview
URL:https://42a1217a.lunarclient-dev.pages.dev

Please sign in to comment.