Skip to content
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

Fix createLaunchScript tasks compiling dependent projects in some cases #145

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
import net.neoforged.moddevgradle.internal.utils.OperatingSystem;
import net.neoforged.moddevgradle.internal.utils.StringUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.jvm.toolchain.JavaToolchainService;
Expand Down Expand Up @@ -61,9 +59,8 @@ abstract class CreateLaunchScriptTask extends DefaultTask {
/**
* Set to the desired Java runtime classpath.
*/
@Classpath
@InputFiles
abstract ConfigurableFileCollection getRuntimeClasspath();
@Input
abstract ListProperty<String> getRuntimeClasspath();

@Input
abstract Property<ModFoldersProvider> getModFolders();
Expand Down Expand Up @@ -125,9 +122,7 @@ private void writeClasspathArguments() throws IOException {
return;
}

var classpathFileList = getRuntimeClasspath().getFiles().stream()
.map(File::getAbsolutePath)
.collect(Collectors.joining(File.pathSeparator));
var classpathFileList = String.join(File.pathSeparator, getRuntimeClasspath().get());

var lines = List.of(
"-classpath",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,19 @@ public void apply(Project project) {
task.setDescription("Creates a bash/shell-script to launch the " + run.getName() + " Minecraft run from outside Gradle or your IDE.");

task.getWorkingDirectory().set(run.getGameDirectory().map(d -> d.getAsFile().getAbsolutePath()));
task.getRuntimeClasspath().setFrom(runtimeClasspathConfig);
// Use a provider indirection to NOT capture a task dependency on the runtimeClasspath.
// Resolving the classpath could require compiling some code depending on the runtimeClasspath setup.
// We don't want to do that on IDE sync!
// In that case, we can't use an @InputFiles ConfigurableFileCollection or Gradle might complain:
// Reason: Task ':createClient2LaunchScript' uses this output of task ':compileApiJava' without
// declaring an explicit or implicit dependency. This can lead to incorrect results being produced,
// depending on what order the tasks are executed.
// So we pass the absolute paths directly...
task.getRuntimeClasspath().set(project.provider(() -> {
return runtimeClasspathConfig.get().getFiles().stream()
.map(File::getAbsolutePath)
.toList();
}));
task.getLaunchScript().set(RunUtils.getLaunchScript(modDevBuildDir, run));
task.getClasspathArgsFile().set(RunUtils.getArgFile(modDevBuildDir, run, RunUtils.RunArgFile.CLASSPATH));
task.getVmArgsFile().set(prepareRunTask.get().getVmArgsFile().map(d -> d.getAsFile().getAbsolutePath()));
Expand Down
Loading