-
-
Notifications
You must be signed in to change notification settings - Fork 1
Port to ModDevGradle #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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>("jar") { | ||
| archiveClassifier.set("slim") | ||
| } | ||
| project.tasks.named<JarJar>(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() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
|
@@ -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) | ||
| } | ||
|
|
||
| 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 | ||
|
|
@@ -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 } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| .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 | ||
|
|
||
|
|
@@ -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>() | ||
There was a problem hiding this comment.
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.