diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java index 04edda60..28e1b066 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java @@ -13,6 +13,7 @@ import org.gradle.plugins.ide.eclipse.model.EclipseModel; import org.gradle.plugins.ide.idea.model.IdeaModel; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.gradle.ext.IdeaExtPlugin; import org.jetbrains.gradle.ext.ProjectSettings; import org.jetbrains.gradle.ext.TaskTriggersConfig; @@ -261,22 +262,30 @@ private void onCommonEclipse(final BiConsumer toPerform) if (!isEclipseImport()) { return; } - - //Grab the eclipse model so we can extend it. -> Done on the root project so that the model is available to all subprojects. - //And so that post sync tasks are only ran once for all subprojects. - EclipseModel model = project.getExtensions().findByType(EclipseModel.class); - if (model == null) { - model = rootProject.getExtensions().findByType(EclipseModel.class); - if (model == null) { - return; - } - } - + + EclipseModel model = getEclipseModel(); + if (model == null) return; + //Configure the project, passing the model and the relevant project. Which does not need to be the root, but can be. toPerform.accept(project, model); }); } - + + /** + * Get the eclipse model from the extensions project. + * + * @return the eclipse model, or {@code null} if not found + */ + public @Nullable EclipseModel getEclipseModel() { + //Grab the eclipse model so we can extend it. -> Done on the root project so that the model is available to all subprojects. + //And so that post sync tasks are only ran once for all subprojects. + EclipseModel model = project.getExtensions().findByType(EclipseModel.class); + if (model == null) { + model = project.getRootProject().getExtensions().findByType(EclipseModel.class); + } + return model; + } + /** * Applies the specified configuration action to configure gradle run projects only. * diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java b/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java index a973d812..b49798d6 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java @@ -267,7 +267,7 @@ public void eclipse(Project project, EclipseModel eclipse) { return; final TaskProvider ideBeforeRunTask = getOrCreateIdeBeforeRunTask(project, runImpl); - final List> copyProcessResourcesTasks = createEclipseCopyResourcesTasks(eclipse, run); + final List> copyProcessResourcesTasks = createEclipseCopyResourcesTasks(run); ideBeforeRunTask.configure(task -> copyProcessResourcesTasks.forEach(task::dependsOn)); try { @@ -327,7 +327,7 @@ public void vscode(Project project, EclipseModel eclipse) final RunImpl runImpl = (RunImpl) run; final TaskProvider ideBeforeRunTask = getOrCreateIdeBeforeRunTask(project, runImpl); - final List> copyProcessResourcesTasks = createEclipseCopyResourcesTasks(eclipse, run); + final List> copyProcessResourcesTasks = createEclipseCopyResourcesTasks(run); ideBeforeRunTask.configure(task -> copyProcessResourcesTasks.forEach(task::dependsOn)); final LaunchConfiguration cfg = launchWriter.createGroup("NG - " + project.getName(), WritingMode.REMOVE_EXISTING) @@ -410,7 +410,7 @@ private List> createIntelliJCopyResourcesTasks(Run run) { return intelliJResourcesTask; } - private List> createEclipseCopyResourcesTasks(EclipseModel eclipse, Run run) { + private List> createEclipseCopyResourcesTasks(Run run) { final List> copyProcessResources = new ArrayList<>(); for (SourceSet sourceSet : run.getModSources().all().get().values()) { final Project sourceSetProject = SourceSetUtils.getProject(sourceSet); @@ -425,7 +425,7 @@ private List> createEclipseCopyResourcesTasks(EclipseModel eclip eclipseResourcesTask = sourceSetProject.getTasks().register(taskName, Copy.class, task -> { final TaskProvider defaultProcessResources = sourceSetProject.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class); task.from(defaultProcessResources.map(ProcessResources::getDestinationDir)); - Path outputDir = eclipse.getClasspath().getDefaultOutputDir().toPath(); + Path outputDir = sourceSetProject.getExtensions().getByType(IdeManagementExtension.class).getEclipseModel().getClasspath().getDefaultOutputDir().toPath(); if (outputDir.endsWith("default")) { // sometimes it has default value from org.gradle.plugins.ide.eclipse.internal.EclipsePluginConstants#DEFAULT_PROJECT_OUTPUT_PATH // which has /default on end that is not present in the final outputDir in eclipse/buildship diff --git a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy index a774678c..ab8c0709 100644 --- a/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy +++ b/userdev/src/functionalTest/groovy/net/neoforged/gradle/userdev/RunTests.groovy @@ -425,13 +425,14 @@ class RunTests extends BuilderBasedTestSpecification { import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; + import net.minecraft.core.registries.Registries; @ExtendWith(EphemeralTestServerProvider.class) public class TestTest { @Test public void testIngredient(MinecraftServer server) { // required to load tags Assertions.assertTrue( - Ingredient.of(ItemTags.AXES).test(Items.DIAMOND_AXE.getDefaultInstance()) + Ingredient.of(server.registryAccess().lookupOrThrow(Registries.ITEM).getOrThrow(ItemTags.AXES)).test(Items.DIAMOND_AXE.getDefaultInstance()) ); } }