Skip to content

Commit

Permalink
Fix multi-project IDE runs and run directory being ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed May 27, 2024
1 parent c652ad5 commit dfee8aa
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void apply(Project project) {
project.getPlugins().apply(JavaLibraryPlugin.class);
var javaExtension = ExtensionUtils.getExtension(project, "java", JavaPluginExtension.class);

project.getPlugins().apply(IdeaExtPlugin.class);
var extension = project.getExtensions().create("neoForge", NeoForgeExtension.class);
var dependencyFactory = project.getDependencyFactory();
var neoForgeModDevLibrariesDependency = extension.getVersion().map(version -> {
Expand Down Expand Up @@ -350,9 +349,8 @@ public void apply(Project project) {
writeLcp.getEntries().from(createArtifacts.get().getResourcesArtifact());
});

var runDirectory = layout.getProjectDirectory().dir("run");
var prepareRunTask = tasks.register(InternalModelHelper.nameOfRun(run, "prepare", "run"), PrepareRunForIde.class, task -> {
task.getGameDirectory().set(runDirectory);
task.getGameDirectory().set(run.getGameDirectory());
task.getVmArgsFile().set(RunUtils.getArgFile(project, run, true));
task.getProgramArgsFile().set(RunUtils.getArgFile(project, run, false));
task.getRunType().set(run.getType());
Expand Down Expand Up @@ -557,6 +555,7 @@ private static void addIntelliJRunConfiguration(Project project,
var sourceSets = ExtensionUtils.getExtension(project, "sourceSets", SourceSetContainer.class);
a.setModuleRef(new ModuleRef(project, sourceSets.getByName("main")));
a.setWorkingDirectory(run.getGameDirectory().get().getAsFile().getAbsolutePath());
System.out.println(a.getWorkingDirectory());

a.setJvmArgs(
RunUtils.escapeJvmArg(RunUtils.getArgFileParameter(prepareTask.getVmArgsFile().get()))
Expand All @@ -569,9 +568,15 @@ private static void addIntelliJRunConfiguration(Project project,
}

private static void configureIntelliJModel(Project project, TaskProvider<Task> ideSyncTask, NeoForgeExtension extension, Map<RunModel, TaskProvider<PrepareRunForIde>> prepareRunTasks) {
var rootProject = project.getRootProject();

if (!rootProject.getPlugins().hasPlugin(IdeaExtPlugin.class)) {
rootProject.getPlugins().apply(IdeaExtPlugin.class);
}

// IDEA Sync has no real notion of tasks or providers or similar
project.afterEvaluate(ignored -> {
var settings = getIntelliJProjectSettings(project);
var settings = getIntelliJProjectSettings(rootProject);
if (settings != null && Boolean.getBoolean("idea.sync.active")) {
// Also run the sync task directly as part of the sync. (Thanks Loom).
var startParameter = project.getGradle().getStartParameter();
Expand All @@ -581,7 +586,7 @@ private static void configureIntelliJModel(Project project, TaskProvider<Task> i
startParameter.setTaskRequests(taskRequests);
}

var runConfigurations = getIntelliJRunConfigurations(project); // TODO: Consider making this a value source
var runConfigurations = getIntelliJRunConfigurations(rootProject); // TODO: Consider making this a value source

if (runConfigurations == null) {
project.getLogger().debug("Failed to find IntelliJ run configuration container. Not adding run configurations.");
Expand Down

0 comments on commit dfee8aa

Please sign in to comment.