Skip to content

Commit

Permalink
build: change build system
Browse files Browse the repository at this point in the history
  • Loading branch information
Syrent committed Jun 1, 2024
1 parent bc54540 commit 98d0e47
Show file tree
Hide file tree
Showing 25 changed files with 602 additions and 127 deletions.
36 changes: 18 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.sayandev.getRelocations
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand All @@ -13,7 +14,7 @@ description = "A modular vanish system for Minecraft servers"

allprojects {
group = "org.sayandev"
version = "1.0.0-rc.3"
version = findProperty("version")!! as String

plugins.apply("java-library")
plugins.apply("maven-publish")
Expand All @@ -23,12 +24,6 @@ allprojects {
repositories {
mavenCentral()
mavenLocal()

// Takenaka
maven("https://repo.screamingsandals.org/public")

maven("https://repo.sayandev.org/snapshots")
maven("https://repo.sayandev.org/releases")
}

tasks {
Expand All @@ -47,17 +42,12 @@ allprojects {

subprojects {
java {
withJavadocJar()
withSourcesJar()

toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}

dependencies {
testImplementation(kotlin("test"))

testImplementation("org.xerial:sqlite-jdbc:3.45.3.0")
testImplementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1")
compileOnly(kotlin("stdlib", version = "2.0.0"))
}

Expand All @@ -78,17 +68,25 @@ subprojects {
archiveFileName.set("${rootProject.name}-${version}-${this@subprojects.name.removePrefix("sayanvanish-")}.jar")
archiveClassifier.set(null as String?)
destinationDirectory.set(file(rootProject.projectDir.path + "/bin"))
relocate("org.sayandev.stickynote", "org.sayandev.sayanvanish.lib.stickynote")
from("LICENSE")
// minimize()
}
}

test {
useJUnitPlatform()
tasks.named<Jar>("sourcesJar") {
getRelocations().forEach { (from, to) ->
val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)")
val textPattern = Regex.fromLiteral(from)
eachFile {
filter {
it.replaceFirst(textPattern, to)
}
path = path.replaceFirst(filePattern, "$1${to.replace('.', '/')}$2")
}
}
}

configurations {
/*configurations {
"apiElements" {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_API))
Expand Down Expand Up @@ -117,12 +115,14 @@ subprojects {
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, project.objects.named(DocsType.SOURCES))
}
}
}
}*/

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
shadow.component(this)
artifact(tasks["sourcesJar"])
// artifact(tasks["java"])
setPom(this)
}
}
Expand Down
24 changes: 24 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.util.*

plugins {
`kotlin-dsl`
`java-library`
kotlin("jvm") version "2.0.0"
id("io.github.goooler.shadow") version "8.1.7"
}

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation("com.github.johnrengelman:shadow:8.1.1")
implementation(gradleApi())
}

val properties = Properties().also { props ->
project.projectDir.resolveSibling("gradle.properties").bufferedReader().use {
props.load(it)
}
}
33 changes: 33 additions & 0 deletions buildSrc/src/main/kotlin/org/sayandev/BuildRelocation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.sayandev

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy

fun getProjectRelocations(): List<BuildRelocation> {
return repositories.map { it.dependencies }
.flatten()
.filter { it.relocation != null }
.map { BuildRelocation(it.relocation!!.from, it.relocation.to, it.modules) }
}

fun Project.getRelocations(): List<BuildRelocation> = getProjectRelocations()

fun getProjectRelocations(module: Module): List<BuildRelocation> {
return getProjectRelocations().filter { it.relocateModules.contains(module) }
}

fun Project.getRelocations(module: Module): List<BuildRelocation> = getProjectRelocations(module)

fun ShadowJar.applyShadowRelocation(module: Module) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
getProjectRelocations(module).forEach { relocate ->
relocate(relocate.from, relocate.to)
}
}

data class BuildRelocation(
val from: String,
val to: String,
val relocateModules: List<Module>
)
35 changes: 35 additions & 0 deletions buildSrc/src/main/kotlin/org/sayandev/Dependency.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.sayandev

data class Dependency(
val group: String,
val artifact: String,
val version: String,
val relocation: Relocation?,
val type: Type,
val modules: List<Module>,
val shadeMethod: ShadeMethod = ShadeMethod.DEFAULT,
) {
constructor(dependency: String, relocation: Relocation?, type: Type, modules: List<Module>) : this(
dependency.substringBefore(':'),
dependency.substringAfter(':').substringBefore(':'),
dependency.substringAfterLast(':'),
relocation,
type,
modules
)

enum class Type(val configurationName: String) {
COMPILE_ONLY("compileOnly"),
IMPLEMENTATION("implementation"),
TEST_IMPLEMENTATION("testImplementation"),
API("api"),
COMPILE_ONLY_API("compileOnlyApi"),
ANNOTATION_PROCESSOR("annotationProcessor"),
}

enum class ShadeMethod {
DEFAULT,
FORCE,
EXCLUDE,
}
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/org/sayandev/Module.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sayandev

enum class Module {
API,
BUKKIT,
VELOCITY,
BUNGEECORD
}
20 changes: 20 additions & 0 deletions buildSrc/src/main/kotlin/org/sayandev/Plugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.sayandev

import org.gradle.kotlin.dsl.PluginDependenciesSpecScope
import org.gradle.kotlin.dsl.version

data class Plugin(
val id: String,
val version: String?,
val modules: List<Module>
)

fun PluginDependenciesSpecScope.applyPlugins(module: Module) {
plugins.filter { plugin -> plugin.modules.contains(module) }.forEach { plugin ->
if (plugin.version != null) {
id(plugin.id) version plugin.version
} else {
id(plugin.id)
}
}
}
9 changes: 9 additions & 0 deletions buildSrc/src/main/kotlin/org/sayandev/Plugins.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sayandev

val plugins = listOf(
Plugin(
"xyz.jpenilla.run-velocity",
"2.3.0",
listOf(Module.VELOCITY)
)
)
6 changes: 6 additions & 0 deletions buildSrc/src/main/kotlin/org/sayandev/Relocation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.sayandev

data class Relocation(
val from: String,
val to: String
)
Loading

0 comments on commit 98d0e47

Please sign in to comment.