Skip to content

Commit

Permalink
Add a property to move multiversion builds to the root builds folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Jun 28, 2024
1 parent d748ec5 commit dc4a855
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/main/kotlin/dev/deftu/gradle/MultiVersionExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.deftu.gradle

import org.gradle.api.Project
import org.gradle.api.provider.Property

abstract class MultiVersionExtension(
val project: Project
) {

abstract val moveBuildsToRootProject: Property<Boolean>

init {
moveBuildsToRootProject.convention(false)
}

}
36 changes: 33 additions & 3 deletions src/main/kotlin/dev/deftu/gradle/multiversion.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package dev.deftu.gradle

import com.replaymod.gradle.preprocess.PreprocessExtension
import com.replaymod.gradle.preprocess.PreprocessPlugin
import dev.deftu.gradle.utils.MCData
import dev.deftu.gradle.utils.ModLoader
import dev.deftu.gradle.utils.setupLoom
import dev.deftu.gradle.utils.*

plugins {
java
}

val mcData = MCData.from(project)
val extension = extensions.create("toolkitMultiversion", MultiVersionExtension::class)

// Set up `loom.platform` and apply Loom
setupLoom(mcData)
Expand All @@ -25,6 +24,37 @@ extensions.configure<PreprocessExtension> {
vars.put("NEOFORGE", if (mcData.isNeoForge) 1 else 0)
}

// Move builds to the new directory if the extension wants us too
afterEvaluate {
if (extension.moveBuildsToRootProject.getOrElse(false)) {
val newBuildDestinationDirectory by lazy {
rootProject.layout.buildDirectory.asFile.get().resolve("versions")
}

fun Jar.moveBuilds() {
destinationDirectory.set(newBuildDestinationDirectory)
}

tasks {
jar {
moveBuilds()
}

if (isLoomPluginPresent) {
named<Jar>("remapJar") {
moveBuilds()
}
}

if (isShadowPluginPresent) {
named<Jar>("fatJar") {
moveBuilds()
}
}
}
}
}

// Define root tasks for ease-of-use
val buildTaskName = "buildVersions"
if (rootProject.tasks.none { task ->
Expand Down

0 comments on commit dc4a855

Please sign in to comment.