Skip to content

Commit

Permalink
feat: sources and shadow Jar files
Browse files Browse the repository at this point in the history
DuoDuoJuZi committed Dec 26, 2024
1 parent 8d76106 commit 2300ccf
Showing 2 changed files with 59 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -27,7 +27,8 @@ jobs:
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew shadowJar
run: ./gradlew build
# run: ./gradlew shadowJar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USERNAME: ${{ github.actor }}
94 changes: 57 additions & 37 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ val modules = rootProject.subprojects.map { it.name }

plugins {
// Java plugin
id("java-library")
id("java-library") apply true

// Fairy framework plugin
id("io.fairyproject") version "0.7.10b2-SNAPSHOT" apply false
@@ -23,7 +23,7 @@ plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.23" apply false

// Shadow plugin, provides the ability to shade fairy and other dependencies to compiled jar
id("com.github.johnrengelman.shadow") version "8.1.1" apply false
id("com.github.johnrengelman.shadow") version "8.1.1" apply true

// Lombok
id("io.freefair.lombok") version "8.11" apply false
@@ -32,20 +32,39 @@ plugins {
id("maven-publish")
}

allprojects {
// Apply Shadow plugin
apply(plugin = "com.github.johnrengelman.shadow")

// Configure repositories
repositories {
mavenCentral()
maven(url = uri("https://oss.sonatype.org/content/repositories/snapshots/"))
maven(url = uri("https://repo.codemc.io/repository/maven-public/"))
maven(url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/"))
maven(url = uri("https://repo.imanity.dev/imanity-libraries"))
maven(url = uri("https://jitpack.io/"))
maven(url = uri("https://repo.papermc.io/repository/maven-public/"))
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
subprojects {
// Plugin
// Apply necessary plugins
apply(plugin = "java-library")
apply(plugin = "io.fairyproject")
apply(plugin = "io.spring.dependency-management")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "io.freefair.lombok")

// Fairy
// Configure dependencies
dependencies {
compileOnlyApi("io.fairyproject:bukkit-platform")
api("io.fairyproject:bukkit-bootstrap")

compileOnlyApi("io.fairyproject:mc-animation")
compileOnlyApi("io.fairyproject:bukkit-command")
compileOnlyApi("io.fairyproject:bukkit-gui")
@@ -60,32 +79,12 @@ subprojects {
compileOnlyApi("io.fairyproject:bukkit-timer")
compileOnlyApi("io.fairyproject:bukkit-nbt")
compileOnlyApi("io.fairyproject:mc-tablist")

compileOnlyApi("dev.folia:folia-api:${properties("spigot.version")}-R0.1-SNAPSHOT")
}
}

allprojects {
// Repositories
repositories {
mavenCentral()
maven(url = uri("https://oss.sonatype.org/content/repositories/snapshots/"))
maven(url = uri("https://repo.codemc.io/repository/maven-public/"))

// Spigot's repository for spigot api dependency
maven(url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/"))
maven(url = uri("https://repo.imanity.dev/imanity-libraries"))

// Jitpack
maven(url = uri("https://jitpack.io/"))

// PaperMc
maven(url = uri("https://repo.papermc.io/repository/maven-public/"))
}
}

subprojects {
tasks.withType(ShadowJar::class.java) {
// Configure ShadowJar task
tasks.withType(ShadowJar::class) {
archiveClassifier.set("shadow")
// Relocate fairy to avoid plugin conflict
relocate("io.fairyproject.bootstrap", "${properties("package")}.fairy.bootstrap")
relocate("net.kyori", "io.fairyproject.libs.kyori")
@@ -96,32 +95,53 @@ subprojects {
relocate("io.github.retrooper.packetevents", "io.fairyproject.libs.packetevents")
relocate("io.fairyproject.bukkit.menu", "${properties("package")}.fairy.menu")
}
}

// Configure sourcesJar task
tasks.register<Jar>("sourcesJar") {
from(sourceSets.main.get().allSource)
archiveClassifier.set("sources")
}
tasks.named("build") {
dependsOn("shadowJar", "sourcesJar")
}
}

publishing {
if (isGitHubActions) {
publications {
modules.forEach { module ->
create<MavenPublication>("maven-${module.capitalize()}") {
// from(components["shadow"])
artifact(tasks.named<ShadowJar>("shadow${module.capitalize()}").get())
groupId = group.toString()
artifactId = "$module"
version = "${properties("version")}-${LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd-MM-yy-hhmmss"))}"
create<MavenPublication>("shadow-${module.capitalize()}") {
project.extensions.configure<com.github.jengelman.gradle.plugins.shadow.ShadowExtension>() {
component(this@create)
//artifact(tasks.named<ShadowJar>("shadowJar").get().archiveFile.get())
groupId = group.toString()
artifactId = "$module"
version = "${properties("version")}-${LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd-MM-yy-hhmmss"))}"
}
}
}
}
// Maven Central
// publications {
// modules.forEach { module ->
// create<MavenPublication>("maven-${module.capitalize()}") {
// artifact(tasks.named<ShadowJar>("shadowJar").get().archiveFile.get())
// groupId = group.toString()
// artifactId = "$module"
// version = "${properties("version")}-${LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd-MM-yy-hhmmss"))}"
// }
// }
// }

// GitHub Packages
repositories {
maven {
url = uri("https://maven.pkg.github.com/LegacyLands/legacy-lands-library")
url = uri("https://maven.pkg.github.com/DuoDuoJuZi/Legacy")
credentials {
username = project.findProperty("githubUsername")?.toString() ?: System.getenv("GITHUB_USERNAME")?.toString() ?: error("GitHub username is missing")
password = project.findProperty("githubToken")?.toString() ?: System.getenv("GITHUB_TOKEN")?.toString() ?: error("GitHub token is missing")
}
}
}
}
}
}

0 comments on commit 2300ccf

Please sign in to comment.