Skip to content

Commit

Permalink
Possibly fix multiloader gradle setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Erdragh committed Oct 24, 2024
1 parent c4712a5 commit 05c3ab0
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 58 deletions.
54 changes: 10 additions & 44 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import java.text.SimpleDateFormat
import java.util.*

plugins {
// Since this mod/bot is written in Kotlin and expected to run on Minecraft and as such
// the JVM, the Kotlin plugin is needed
alias(libs.plugins.kotlin)
// For generating documentation based on comments in the code
alias(libs.plugins.dokka)
java
Expand Down Expand Up @@ -39,16 +36,6 @@ subprojects {
val modAuthor: String by project
val isCommon = modLoader == rootProject.projects.common.name

base {
// This will be the final name of the exported JAR file
archivesName.set("$modId-$modLoader-$minecraftVersion")
}

extensions.configure<JavaPluginExtension> {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
withSourcesJar()
}

repositories {
mavenCentral()
maven(url = "https://maven.neoforged.net/releases/")
Expand Down Expand Up @@ -76,11 +63,8 @@ subprojects {
val runtimeLib by configurations.registering {
isTransitive = false
}
// Configuration for depending on the common project
val commonDep by configurations.creating
configurations.implementation.extendsFrom(configurations.named(includeBotDep.name))
configurations.implementation.extendsFrom(configurations.named(runtimeLib.name))
configurations.implementation.extendsFrom(configurations.named(commonDep.name))

dependencies {
arrayOf(
Expand All @@ -91,16 +75,16 @@ subprojects {

// Library used to communicate with Discord, see https://jda.wiki
rootProject.jda.jda,
// JDA's dependencies
rootProject.jda.commons.collections,
rootProject.jda.trove4j,
rootProject.jda.jackson.annotations,
rootProject.jda.jackson.core,
rootProject.jda.jackson.databind,
rootProject.jda.websocket,
rootProject.jda.okhttp,
rootProject.jda.okio,
rootProject.jda.tink,
// JDA's dependencies
rootProject.jda.commons.collections,
rootProject.jda.trove4j,
rootProject.jda.jackson.annotations,
rootProject.jda.jackson.core,
rootProject.jda.jackson.databind,
rootProject.jda.websocket,
rootProject.jda.okhttp,
rootProject.jda.okio,
rootProject.jda.tink,
// Library used for sending messages via Discord Webhooks
rootProject.dcwebhooks.webhooks,
rootProject.dcwebhooks.json,
Expand Down Expand Up @@ -196,20 +180,6 @@ subprojects {
inputs.properties(expandProps)
}

if (!isCommon) {
dependencies {
commonDep(project(":common")) {
isTransitive = false
}
}

tasks.jar {
dependsOn(project(":common").tasks.jar)
from(project(":common").sourceSets.main.get().output)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}

// 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.
Expand Down Expand Up @@ -268,10 +238,6 @@ subprojects {
}
}

kotlin {
jvmToolchain(21)
}


// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
idea {
Expand Down
11 changes: 11 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id("groovy-gradle-plugin")
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20")
}

repositories {
mavenCentral()
}
101 changes: 101 additions & 0 deletions buildSrc/src/main/groovy/multiloader-common.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
plugins {
id 'java-library'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm"
}

base {
archivesName = "${modId}-${project.name}-${minecraftVersion}"
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(javaVersion)
withSourcesJar()
withJavadocJar()
}

kotlin {
jvmToolchain(Integer.parseInt(javaVersion))
}

repositories {
mavenCentral()
// https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_content_exclusively_found_in_one_repository
exclusiveContent {
forRepository {
maven {
name = 'Sponge'
url = 'https://repo.spongepowered.org/repository/maven-public'
}
}
filter { includeGroupAndSubgroups('org.spongepowered') }
}
exclusiveContent {
forRepositories(
maven {
name = 'ParchmentMC'
url = 'https://maven.parchmentmc.org/'
},
maven {
name = "NeoForge"
url = 'https://maven.neoforged.net/releases'
}
)
filter { includeGroup('org.parchmentmc.data') }
}
maven {
name = 'BlameJared'
url = 'https://maven.blamejared.com'
}
}

// Declare capabilities on the outgoing configurations.
// Read more about capabilities here: https://docs.gradle.org/current/userguide/component_capabilities.html#sec:declaring-additional-capabilities-for-a-local-component
['apiElements', 'runtimeElements', 'sourcesElements', 'javadocElements'].each { variant ->
configurations."$variant".outgoing {
capability("$group:${base.archivesName.get()}:$version")
capability("$group:$modId-${project.name}-${minecraftVersion}:$version")
capability("$group:$modId:$version")
}
publishing.publications.configureEach {
suppressPomMetadataWarningsFor(variant)
}
}

sourcesJar {
from(rootProject.file('LICENSE')) {
rename { "${it}_${title}" }
}
}

jar {
from(rootProject.file('LICENSE')) {
rename { "${it}_${title}" }
}

manifest {
attributes([
'Specification-Title' : title,
'Specification-Vendor' : modAuthor,
'Specification-Version' : project.jar.archiveVersion,
'Implementation-Title' : project.name,
'Implementation-Version': project.jar.archiveVersion,
'Implementation-Vendor' : modAuthor,
'Built-On-Minecraft' : minecraftVersion
])
}
}

publishing {
publications {
register('mavenJava', MavenPublication) {
artifactId base.archivesName.get()
from components.java
}
}
repositories {
maven {
url System.getenv('local_maven_url')
}
}
}
57 changes: 57 additions & 0 deletions buildSrc/src/main/groovy/multiloader-loader.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
plugins {
id 'multiloader-common'
id "org.jetbrains.kotlin.jvm"
}

configurations {
commonJava {
canBeResolved = true
}
commonKotlin {
canBeResolved = true
}
commonResources {
canBeResolved = true
}
}

dependencies {
compileOnly(project(':common')) {
capabilities {
requireCapability "$group:$modId"
}
}
commonJava project(path: ':common', configuration: 'commonJava')
commonKotlin project(path: ":common", configuration: "commonKotlin")
commonResources project(path: ':common', configuration: 'commonResources')
}

tasks.named('compileJava', JavaCompile) {
dependsOn(configurations.commonJava)
source(configurations.commonJava)
}

tasks.named("compileKotlin") {
dependsOn(configurations.commonKotlin)
source(configurations.commonJava)
source(configurations.commonKotlin)
}

processResources {
dependsOn(configurations.commonResources)
from(configurations.commonResources)
}

tasks.named('javadoc', Javadoc).configure {
dependsOn(configurations.commonJava)
source(configurations.commonJava)
}

tasks.named('sourcesJar', Jar) {
dependsOn(configurations.commonJava)
from(configurations.commonJava)
dependsOn(configurations.commonKotlin)
from(configurations.commonKotlin)
dependsOn(configurations.commonResources)
from(configurations.commonResources)
}
30 changes: 29 additions & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
idea
java
alias(libs.plugins.kotlin)
id("multiloader-common")
alias(libs.plugins.moddev)
}

Expand All @@ -15,6 +15,13 @@ val modId: String by project
neoForge {
neoFormVersion = neoformVersion

// Automatically enable neoforge AccessTransformers if the file exists
// This location is hardcoded in FML and can not be changed.
// https://github.com/neoforged/FancyModLoader/blob/a952595eaaddd571fbc53f43847680b00894e0c1/loader/src/main/java/net/neoforged/fml/loading/moddiscovery/ModFile.java#L118
val transformerFile = project(":common").file("src/main/resources/META-INF/accesstransformer.cfg")
if (transformerFile.exists())
accessTransformers.from(transformerFile)

parchment {
minecraftVersion = parchmentMinecraft
mappingsVersion = parchmentVersion
Expand All @@ -27,4 +34,25 @@ dependencies {
api("fuzs.forgeconfigapiport:forgeconfigapiport-common-neoforgeapi:$forgeConfigAPIVersion")
compileOnly("org.spongepowered:mixin:0.8.7")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
}

configurations {
create("commonJava") {
isCanBeResolved = false
isCanBeConsumed = true
}
create("commonKotlin") {
isCanBeResolved = false
isCanBeConsumed = true
}
create("commonResources") {
isCanBeResolved = false
isCanBeConsumed = true
}
}

artifacts {
add("commonJava", sourceSets.main.get().java.sourceDirectories.singleFile)
add("commonKotlin", sourceSets.main.get().kotlin.sourceDirectories.filter { !it.name.endsWith("java") }.singleFile)
add("commonResources", sourceSets.main.get().resources.sourceDirectories.singleFile)
}
4 changes: 1 addition & 3 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import me.modmuss50.mpp.platforms.modrinth.ModrinthOptions

plugins {
java
alias(libs.plugins.kotlin)
idea
id("multiloader-loader")
alias(libs.plugins.loom)
alias(libs.plugins.publish)
}
Expand Down Expand Up @@ -41,8 +41,6 @@ loom {

@Suppress("UnstableApiUsage")
mixin {
// TODO: Somehow figure out a way to get loom to create a refmap for common mixins
// add(project(":common").sourceSets.main.get())
defaultRefmapName.set("${modId}.refmap.json")
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
kotlin.code.style=official
org.gradle.jvmargs=-Xmx3G -XX:ThreadStackSize=4096 -XX:CompilerThreadStackSize=4096

javaVersion=21

# Minecraft things
enabledPlatforms=fabric,neoforge

Expand Down
Loading

0 comments on commit 05c3ab0

Please sign in to comment.