diff --git a/build.gradle.kts b/build.gradle.kts index 8b1c43b..146c151 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,14 +11,14 @@ 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 { @@ -26,7 +26,7 @@ gradlePlugin { 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" } } diff --git a/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/HelperExtension.kt b/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/HelperExtension.kt index 32aa70d..9a49c7f 100644 --- a/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/HelperExtension.kt +++ b/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/HelperExtension.kt @@ -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 @@ -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") { - archiveClassifier.set("slim") - } - project.tasks.named(DefaultJarJarFeature.JAR_JAR_TASK_NAME) { - archiveClassifier.set("") - } - } - private lateinit var apiSourceSet: SourceSet fun withApiSourceSet() { if (::apiSourceSet.isInitialized) return @@ -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) @@ -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) } } @@ -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 } } @@ -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() programArgument("--nogui") } } } - fun withDataGenRuns(cfg: Action = Action{}) { - project.runs.maybeCreate("data").apply { - singleInstance() + fun withDataGenRuns(cfg: Action = Action{}) { + project.neoForge.runs.create("data").apply { + // TODO singleInstance() programArguments.add("--mod") programArguments.add(projectId) programArguments.add("--all") @@ -290,12 +296,13 @@ open class HelperExtension @Inject constructor(private val project: Project) { } } - fun withGameTestRuns(cfg: Action = Action{}) { - project.runs.matching { it.name != "data" }.all { + fun withGameTestRuns(cfg: Action = Action{}) { + 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) } diff --git a/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/HelperPlugin.kt b/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/HelperPlugin.kt index dfa1867..fac2770 100644 --- a/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/HelperPlugin.kt +++ b/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/HelperPlugin.kt @@ -26,7 +26,7 @@ class HelperPlugin : Plugin { with(project) { apply() apply() - apply(plugin = "net.neoforged.gradle.userdev") + apply(plugin = "net.neoforged.moddev") val helperExtension = setupExtensions() setupPublishing(helperExtension) @@ -34,6 +34,7 @@ class HelperPlugin : Plugin { setupRepositories() configureTasks(helperExtension) setupArtifacts() + neoForge.version.set(helperExtension.neoVersion) } } diff --git a/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/Util.kt b/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/Util.kt index 2b24689..7f908b7 100644 --- a/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/Util.kt +++ b/src/main/kotlin/com/github/minecraftschurlimods/helperplugin/Util.kt @@ -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 @@ -24,9 +20,9 @@ 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): Provider = name.map(TransformerUtils.guard { - return@guard if (hasProperty(it)) property(it)?.toString() else null -}) +fun Project.localGradleProperty(name: Provider): Provider = name + .filter { hasProperty(it) && property(it) != null } + .map { property(it)!!.toString() } fun Project.localGradleProperty(name: String): Provider = localGradleProperty(provider { name }) @@ -34,8 +30,7 @@ val Project.base: BasePluginExtension get() = this.the() val Project.java: JavaPluginExtension get() = this.the() val Project.sourceSets: SourceSetContainer get() = this.the() val Project.publishing: PublishingExtension get() = this.the() -val Project.runs: NamedDomainObjectContainer get() = this.extensions.getByName("runs") as NamedDomainObjectContainer -val Project.jarJar: JarJar get() = this.the() +val Project.neoForge: NeoForgeExtension get() = this.the() val SoftwareComponentContainer.java: JvmSoftwareComponentInternal get() = this.getByName("java") as JvmSoftwareComponentInternal @@ -58,4 +53,3 @@ operator fun JavaPluginExtension.invoke(action: Action) = a operator fun PublishingExtension.invoke(action: Action) = action.execute(this) val NamedDomainObjectProvider.version: Provider get() = flatMap { it.version } -val Run.idea:IdeaRunExtension get() = the()