Skip to content

Commit

Permalink
Fixes in afterevaluate ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed May 26, 2024
1 parent 808bd0a commit 187743d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Collection<SourceSet>> sourceSets = run.getModSources().map(modSources -> {
Expand All @@ -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;
}

Expand Down

0 comments on commit 187743d

Please sign in to comment.