Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ repositories {
}

group = "com.github.minecraftschurlimods"
version = "1.14"
version = "2.0"
base.archivesName = "HelperPlugin"

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

dependencies {
implementation("com.akuleshov7:ktoml-core:0.5.1")
implementation("net.neoforged.gradle:userdev:[7.0.142,)")
implementation("net.neoforged:moddev-gradle:1.0.15")
}

gradlePlugin {
plugins {
create("helper") {
id = "com.github.minecraftschurlimods.helperplugin"
displayName = "Helper Plugin"
description = "A gradle helper plugin built on-top of the neoforged/NeoGradle plugin"
description = "A gradle helper plugin built on-top of the neoforged/ModDevGradle plugin"
implementationClass = "com.github.minecraftschurlimods.helperplugin.HelperPlugin"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ package com.github.minecraftschurlimods.helperplugin

import com.github.minecraftschurlimods.helperplugin.moddependencies.ModDependency
import com.github.minecraftschurlimods.helperplugin.moddependencies.ModDependencyContainer
import net.neoforged.gradle.common.extensions.DefaultJarJarFeature
import net.neoforged.gradle.common.tasks.JarJar
import net.neoforged.gradle.dsl.common.runs.run.Run
import net.neoforged.moddevgradle.dsl.RunModel
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
Expand Down Expand Up @@ -171,21 +169,10 @@ open class HelperExtension @Inject constructor(private val project: Project) {
LIBRARY("GAMELIBRARY")
}

private val neoforgeDependency = neoVersion.map { project.dependencyFactory.create("net.neoforged", "neoforge", it) }
private val testframeworkDependency = neoVersion.map { project.dependencyFactory.create("net.neoforged", "testframework", it) }

fun neoforge() = neoforgeDependency
fun testframework() = testframeworkDependency

fun withJarJar() {
project.tasks.named<Jar>("jar") {
archiveClassifier.set("slim")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I removed this because MDG will add the jarjar stuff to the normal jar directly. It is possible to create a slim jar manually but it shouldn't be necessary.

}
project.tasks.named<JarJar>(DefaultJarJarFeature.JAR_JAR_TASK_NAME) {
archiveClassifier.set("")
}
}

private lateinit var apiSourceSet: SourceSet
fun withApiSourceSet() {
if (::apiSourceSet.isInitialized) return
Expand All @@ -194,7 +181,8 @@ open class HelperExtension @Inject constructor(private val project: Project) {
usingSourceSet(apiSourceSet)
}
project.dependencies {
apiSourceSet.compileOnlyConfigurationName(neoforge())
project.neoForge.addModdingDependenciesTo(apiSourceSet)
// TODO is the line above a suitable replacement? apiSourceSet.compileOnlyConfigurationName(neoforge())
"implementation"(apiSourceSet.output)
if (::testSourceSet.isInitialized) {
testSourceSet.implementationConfigurationName(apiSourceSet.output)
Expand All @@ -212,8 +200,8 @@ open class HelperExtension @Inject constructor(private val project: Project) {
project.tasks.apiJar {
from(apiSourceSet.allSource)
}
project.runs.all {
modSources.add(apiSourceSet)
project.neoForge.mods.all {
sourceSet(apiSourceSet)
}
}

Expand All @@ -223,14 +211,17 @@ open class HelperExtension @Inject constructor(private val project: Project) {
testSourceSet = project.sourceSets.maybeCreate("test")
project.dependencies {
testSourceSet.implementationConfigurationName(project.sourceSets.main.output)
testSourceSet.implementationConfigurationName(neoforge())
project.neoForge.addModdingDependenciesTo(testSourceSet)
// TODO is the line above a suitable replacement? testSourceSet.implementationConfigurationName(neoforge())
if (::apiSourceSet.isInitialized) {
testSourceSet.implementationConfigurationName(apiSourceSet.output)
}
}
project.runs.matching { it.name != "data" }.all {
modSources.add(testSourceSet)
idea.primarySourceSet = testSourceSet
project.neoForge.mods.matching { it.name == "for_other_runs" }.all {
sourceSet(testSourceSet)
}
project.neoForge.runs.matching { it.name != "data" }.all {
sourceSet = testSourceSet
}
}

Expand All @@ -240,39 +231,54 @@ open class HelperExtension @Inject constructor(private val project: Project) {
dataGenSourceSet = project.sourceSets.maybeCreate("data")
project.dependencies {
dataGenSourceSet.implementationConfigurationName(project.sourceSets.main.output)
dataGenSourceSet.implementationConfigurationName(neoforge())
project.neoForge.addModdingDependenciesTo(dataGenSourceSet)
// TODO is the line above a suitable replacement? dataGenSourceSet.implementationConfigurationName(neoforge())
if (::apiSourceSet.isInitialized) {
dataGenSourceSet.implementationConfigurationName(apiSourceSet.output)
}
}
project.runs.matching { it.name == "data" }.all {
modSources.add(dataGenSourceSet)
idea.primarySourceSet = dataGenSourceSet
project.neoForge.mods.matching { it.name == "for_data_run" }.all {
sourceSet(dataGenSourceSet)
}
project.neoForge.runs.matching { it.name == "data" }.all {
sourceSet = dataGenSourceSet
}
}

fun withCommonRuns() {
project.runs {
val dataModModel = project.neoForge.mods.create("for_data_run")
dataModModel.sourceSet(project.sourceSets.main.get())
val otherRunsModModel = project.neoForge.mods.create("for_other_runs")
otherRunsModModel.sourceSet(project.sourceSets.main.get())

project.neoForge.runs {
all {
workingDirectory.set(project.layout.projectDirectory.dir("run"))
gameDirectory.set(project.layout.projectDirectory.dir("run"))
systemProperties.put("forge.logging.markers", "REGISTRIES")
systemProperties.put("forge.logging.console.level", "debug")
if (!runningInCI.getOrElse(false)) {
jvmArgument("-XX:+AllowEnhancedClassRedefinition")
}
modSources.add(project.sourceSets.main.get())
if (name == "data") {
mods = listOf(dataModModel)
} else {
mods = listOf(otherRunsModModel)
}
}
create("client") {
client()
}
maybeCreate("client")
maybeCreate("server").apply {
singleInstance()
create("server") {
server()
// TODO singleInstance()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not (yet) supported by MDG as far as I know. Does this only control the IDEA run? If so it should be trivial to add.

programArgument("--nogui")
}
}
}

fun withDataGenRuns(cfg: Action<Run> = Action<Run>{}) {
project.runs.maybeCreate("data").apply {
singleInstance()
fun withDataGenRuns(cfg: Action<RunModel> = Action<RunModel>{}) {
project.neoForge.runs.create("data").apply {
// TODO singleInstance()
programArguments.add("--mod")
programArguments.add(projectId)
programArguments.add("--all")
Expand All @@ -290,12 +296,13 @@ open class HelperExtension @Inject constructor(private val project: Project) {
}
}

fun withGameTestRuns(cfg: Action<Run> = Action<Run>{}) {
project.runs.matching { it.name != "data" }.all {
fun withGameTestRuns(cfg: Action<RunModel> = Action<RunModel>{}) {
project.neoForge.runs.matching { it.name != "data" }.all {
systemProperties.put("neoforge.enabledGameTestNamespaces", projectId)
}
project.runs.maybeCreate("gameTestServer").apply {
singleInstance()
project.neoForge.runs.create("gameTestServer").apply {
type = "gameTestServer"
// TODO singleInstance()
jvmArgument("-ea")
cfg.execute(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ class HelperPlugin : Plugin<Project> {
with(project) {
apply<JavaPlugin>()
apply<MavenPublishPlugin>()
apply(plugin = "net.neoforged.gradle.userdev")
apply(plugin = "net.neoforged.moddev")

val helperExtension = setupExtensions()
setupPublishing(helperExtension)
setupJava(helperExtension)
setupRepositories()
configureTasks(helperExtension)
setupArtifacts()
neoForge.version.set(helperExtension.neoVersion)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.github.minecraftschurlimods.helperplugin

import com.github.minecraftschurlimods.helperplugin.moddependencies.ModDependency
import net.neoforged.gradle.dsl.common.extensions.JarJar
import net.neoforged.gradle.dsl.common.runs.ide.extensions.IdeaRunExtension
import net.neoforged.gradle.dsl.common.runs.run.Run
import net.neoforged.gradle.util.TransformerUtils
import net.neoforged.moddevgradle.dsl.NeoForgeExtension
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.Project
import org.gradle.api.component.SoftwareComponentContainer
Expand All @@ -24,18 +20,17 @@ import org.gradle.kotlin.dsl.the
import org.gradle.language.jvm.tasks.ProcessResources

// TODO: remove this once https://github.com/gradle/gradle/issues/23572 is fixed
fun Project.localGradleProperty(name: Provider<String>): Provider<String> = name.map(TransformerUtils.guard {
return@guard if (hasProperty(it)) property(it)?.toString() else null
})
fun Project.localGradleProperty(name: Provider<String>): Provider<String> = name
.filter { hasProperty(it) && property(it) != null }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Incubating API, but MDG uses it internally anyway and I don't see a good alternative that preserves nullability safety. (Otherwise we'd need a Provider<String?>).

.map { property(it)!!.toString() }

fun Project.localGradleProperty(name: String): Provider<String> = localGradleProperty(provider { name })

val Project.base: BasePluginExtension get() = this.the<BasePluginExtension>()
val Project.java: JavaPluginExtension get() = this.the<JavaPluginExtension>()
val Project.sourceSets: SourceSetContainer get() = this.the<SourceSetContainer>()
val Project.publishing: PublishingExtension get() = this.the<PublishingExtension>()
val Project.runs: NamedDomainObjectContainer<Run> get() = this.extensions.getByName("runs") as NamedDomainObjectContainer<Run>
val Project.jarJar: JarJar get() = this.the<JarJar>()
val Project.neoForge: NeoForgeExtension get() = this.the<NeoForgeExtension>()

val SoftwareComponentContainer.java: JvmSoftwareComponentInternal get() = this.getByName("java") as JvmSoftwareComponentInternal

Expand All @@ -58,4 +53,3 @@ operator fun JavaPluginExtension.invoke(action: Action<JavaPluginExtension>) = a
operator fun PublishingExtension.invoke(action: Action<PublishingExtension>) = action.execute(this)

val NamedDomainObjectProvider<ModDependency>.version: Provider<String> get() = flatMap { it.version }
val Run.idea:IdeaRunExtension get() = the<IdeaRunExtension>()