Skip to content

Commit

Permalink
Merge pull request #58 from PssbleTrngle/feature/gradle-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle authored Jul 20, 2023
2 parents c841177 + 082a918 commit 2b5e5e0
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 554 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: ./gradlew build sonarqube
run: ./gradlew build sonar
26 changes: 1 addition & 25 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
val minecraft_version: String by extra
val mod_version: String by extra
val mod_id: String by extra
val xmlutil_version: String by extra

plugins {
id("org.spongepowered.gradle.vanilla") version ("0.2.1-SNAPSHOT")
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.serialization")
}

base {
archivesName.set("${mod_id}-api")
}

minecraft {
version(minecraft_version)
}

dependencies {
compileOnly("org.spongepowered:mixin:0.8.5")

implementation("io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}")
implementation("io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}")
}
common()
161 changes: 20 additions & 141 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,89 +1,25 @@
import groovy.util.Node
import groovy.util.NodeList
import java.time.LocalDateTime

val mod_version: String by extra
val mod_name: String by extra
val mod_id: String by extra
val mod_author: String by extra
val minecraft_version: String by extra
val repository: String by extra
val artifactGroup: String by extra
val mod_version: String by extra
val xmlutil_version: String by extra

plugins {
java
idea
id("maven-publish")
id("org.jetbrains.kotlin.jvm") version ("1.8.21") apply (false)
id("org.jetbrains.kotlin.plugin.serialization") version ("1.8.21") apply (false)
id("org.sonarqube") version "4.2.0.3129"
id("net.somethingcatchy.gradle") version ("0.0.6")
}

subprojects {
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.kotlin.jvm")

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
withJavadocJar()
}

tasks.withType<Jar> {
val now = LocalDateTime.now().toString()

duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(rootProject.file("LICENSE")) {
rename { "${it}_${mod_name}" }
}

manifest {
attributes(
mapOf(
"Specification-Title" to mod_name,
"Specification-Vendor" to mod_author,
"Specification-Version" to mod_version,
"Implementation-Title" to name,
"Implementation-Version" to archiveVersion,
"Implementation-Vendor" to mod_author,
"Implementation-Timestamp" to now,
)
)
}
}
withKotlin()

//tasks.named<Jar>("sourcesJar") {
// duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// from(rootProject.file("LICENSE")) {
// rename { "${it}_${mod_name}" }
// }
//}
mod {
includedLibraries.set(setOf(
"io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}",
"io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}",
))
}

subprojects {
repositories {
mavenCentral()

maven {
url = uri("https://repo.spongepowered.org/repository/maven-public/")
content {
includeGroup("org.spongepowered")
}
}

maven {
url = uri("https://api.modrinth.com/maven")
content {
includeGroup("maven.modrinth")
}
}

maven {
url = uri("https://www.cursemaven.com")
content {
includeGroup("curse.maven")
}
}
modrinthMaven()
curseMaven()

maven {
url = uri("https://maven.theillusivec4.top/")
Expand All @@ -93,82 +29,25 @@ subprojects {
}

maven {
url = uri("https://thedarkcolour.github.io/KotlinForForge/")
url = uri("https://maven.blamejared.com")
content {
includeGroup("thedarkcolour")
includeGroup("vazkii.botania")
}
}
}

// Disables Gradle's custom module metadata from being published to maven. The
// metadata includes mapped dependencies which are not reasonably consumable by
// other mod developers.
tasks.withType<GenerateModuleMetadata> {
enabled = false
}

tasks.withType<ProcessResources> {
// this will ensure that this task is redone when the versions change.
inputs.property("version", version)

filesMatching(listOf("META-INF/mods.toml", "pack.mcmeta", "fabric.mod.json", "${mod_id}.mixins.json")) {
expand(
mapOf(
"mod_version" to mod_version,
"mod_name" to mod_name,
"mod_id" to mod_id,
"mod_author" to mod_author,
"repository" to repository,
)
)
}
}

val env = System.getenv()

publishing {
enablePublishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${repository}")
version = mod_version
credentials {
username = env["GITHUB_ACTOR"]
password = env["GITHUB_TOKEN"]
}
}
}
publications {
create<MavenPublication>("gpr") {
groupId = artifactGroup
artifactId = "${mod_id}-${project.name}"
version = mod_version
from(components["java"])

pom.withXml {
val node = asNode()
val list = node.get("dependencies") as NodeList
list.forEach { node.remove(it as Node) }
}
}
githubPackages(this@subprojects)
}
}
}

sonarqube {
properties {
property("sonar.projectVersion", version)
property("sonar.projectKey", mod_id)
tasks.withType<Jar> {
exclude("datapacks")
}
}

subprojects {
sonarqube {
properties {
property("sonar.branch", this@subprojects.name)
}
}
}
enableSonarQube()

idea {
module.excludeDirs.add(file("web"))
Expand Down
34 changes: 9 additions & 25 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
val minecraft_version: String by extra
val mod_version: String by extra
val mod_id: String by extra
val xmlutil_version: String by extra

plugins {
id("org.spongepowered.gradle.vanilla") version ("0.2.1-SNAPSHOT")
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.serialization")
}

base {
archivesName.set("${mod_id}-common")
jacoco
}

minecraft {
version(minecraft_version)
common {
dependOn(project(":api"))
}

dependencies {
compileOnly("org.spongepowered:mixin:0.8.5")

implementation("io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}")
implementation("io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}")

testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("io.github.origin-energy:java-snapshot-testing-junit5:4.0.6")

implementation(project(":api"))
}

sourceSets["main"].resources {
srcDir(project.file("src/generated/resources"))
}

tasks.test {
Expand All @@ -39,4 +17,10 @@ tasks.test {
events("passed", "skipped", "failed")
}
workingDir = project.file("run")

finalizedBy(tasks.jacocoTestReport)
}

tasks.jacocoTestReport {
dependsOn(tasks.test)
}
93 changes: 8 additions & 85 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,94 +1,17 @@
val minecraft_version: String by extra
val mod_version: String by extra
val mod_id: String by extra
val fabric_loader_version: String by extra
val fabric_version: String by extra
val xmlutil_version: String by extra
val create_fabric_version: String by extra

plugins {
id("fabric-loom") version ("1.0-SNAPSHOT")
id("idea")
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.serialization")
}
fabric {
enableMixins()

base {
archivesName.set("${mod_id}-fabric")
}
dataGen()

val dependencyProjects = listOf(
project(":api"),
project(":common"),
)
dependOn(project(":api"))
dependOn(project(":common"))
}

dependencies {
minecraft("com.mojang:minecraft:${minecraft_version}")
mappings(loom.officialMojangMappings())

modImplementation("net.fabricmc:fabric-loader:${fabric_loader_version}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${fabric_version}")

implementation(include("io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}")!!)
implementation(include("io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}")!!)

modImplementation("net.fabricmc:fabric-language-kotlin:1.9.1+kotlin.1.8.10")

modRuntimeOnly("maven.modrinth:create-fabric:${create_fabric_version}")

dependencyProjects.forEach { implementation(it) }
}

loom {
//accessWidenerPath.set(file("src/main/resources/${mod_id}.accesswidener"))
mixin {
defaultRefmapName.set("${mod_id}.refmap.json")
}

runs {
named("client") {
client()
configName = "Fabric Client"
runDir("run")
}
named("server") {
server()
configName = "Fabric Server"
runDir("run/server")
}
create("data ") {
client()
configName = "Fabric Datagen"
runDir("run/datagen")

vmArg("-Dfabric-api.datagen")
vmArg("-Dfabric-api.datagen.output-dir=${project(":common").file("src/generated/resources")}")
vmArg("-Dfabric-api.datagen.modid=${mod_id}")
}
forEach { run ->
run.ideConfigGenerated(true)
}
}

mods {
create(mod_id) {
sourceSet(sourceSets.main.get())
dependencyProjects.forEach {
sourceSet(it.sourceSets.main.get())
}
}
}
}

tasks.withType<JavaCompile> {
dependencyProjects.forEach {
source(it.sourceSets["main"].allSource)
}
}

tasks.jar {
from(sourceSets.main.get().output)
dependencyProjects.forEach {
from(it.sourceSets.main.get().output)
}
}
uploadToCurseforge()
uploadToModrinth()
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"fabricloader": ">=0.14",
"fabric": "*",
"minecraft": ">=1.19.2",
"fabric-language-kotlin": ">=1.7.1+kotlin.1.6.10",
"fabric-language-kotlin": "^1.9.0",
"java": ">=17"
}
}
Expand Down
Loading

0 comments on commit 2b5e5e0

Please sign in to comment.