From 187743d87c7193ac2963360af12473af2e30b133 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Sun, 26 May 2024 16:07:02 +0300 Subject: [PATCH] Fixes in afterevaluate ordering --- .../gradle/common/CommonProjectPlugin.java | 10 +++++-- .../gradle/common/util/run/RunsUtil.java | 30 +++++++++---------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java b/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java index db3be1143..223cb471a 100644 --- a/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java +++ b/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java @@ -178,8 +178,6 @@ private void configureSourceSetConventions(Project project, Conventions conventi if (sourceSets.getShouldMainSourceSetBeAutomaticallyAddedToRuns().get()) { //We always register main run.getModSources().add(project.getExtensions().getByType(SourceSetContainer.class).getByName("main")); - if (run.getIsJUnit().get()) - run.getUnitTestSources().add(project.getExtensions().getByType(SourceSetContainer.class).getByName("test")); } if (sourceSets.getShouldSourceSetsLocalRunRuntimesBeAutomaticallyAddedToRuns().get() && configurations.getIsEnabled().get()) @@ -329,6 +327,14 @@ private void applyAfterEvaluate(final Project project) { if (run instanceof RunImpl) { run.configure(); + // We add default junit sourcesets here because we need to know the type of the run first + final Conventions conventions = project.getExtensions().getByType(Subsystems.class).getConventions(); + if (conventions.getIsEnabled().get() && conventions.getSourceSets().getIsEnabled().get() && conventions.getSourceSets().getShouldMainSourceSetBeAutomaticallyAddedToRuns().get()) { + if (run.getIsJUnit().get()) { + run.getUnitTestSources().add(project.getExtensions().getByType(SourceSetContainer.class).getByName("test")); + } + } + if (run.getConfigureFromDependencies().get()) { final RunImpl runImpl = (RunImpl) run; diff --git a/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java b/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java index ed5ffadb5..363fd25be 100644 --- a/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java +++ b/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java @@ -52,21 +52,7 @@ public static String createTaskName(final String prefix, final Run run) { public static Run create(final Project project, final String name) { final RunImpl run = project.getObjects().newInstance(RunImpl.class, project, name); - project.afterEvaluate(evaluatedProject -> { - if (!run.getIsJUnit().get()) { - //Create run exec tasks for all none unit test runs - project.getTasks().register(createTaskName(name), RunExec.class, runExec -> { - runExec.getRun().set(run); - addRunSourcesDependenciesToTask(runExec, run); - - run.getTaskDependencies().forEach(runExec::dependsOn); - }); - } else { - createOrReuseTestTask(project, name, run); - } - }); - - //Configure mod sources when needed + //Configure mod sources env vars project.afterEvaluate(evaluatedProject -> { //Create a combined provider for the mod and unit test sources Provider> sourceSets = run.getModSources().map(modSources -> { @@ -81,6 +67,20 @@ public static Run create(final Project project, final String name) { run.getEnvironmentVariables().put("MOD_CLASSES", buildGradleModClasses(sourceSets)); }); + project.afterEvaluate(evaluatedProject -> { + if (!run.getIsJUnit().get()) { + //Create run exec tasks for all non-unit test runs + project.getTasks().register(createTaskName(name), RunExec.class, runExec -> { + runExec.getRun().set(run); + addRunSourcesDependenciesToTask(runExec, run); + + run.getTaskDependencies().forEach(runExec::dependsOn); + }); + } else { + createOrReuseTestTask(project, name, run); + } + }); + return run; }