Skip to content

Commit 3a74288

Browse files
committed
Allow genEclipseRuns to be executed without the Eclipse plugin
The point of requiring the Eclipse plugin for `genEclipseRuns` was to get the accurate compiler output directory and project name as defined by the Eclipse project. However, the absense of the task itself can cause issues in various buildscript setups. Since it is generally difficult to configure these attributes for an Eclipse project, the task will now run without the Eclipse plugin and use best-guess defaults for these values. However, a warning will be emitted to the problems reporter if any Eclipse run config generation task is run without the Eclipse plugin being loaded.
1 parent 08aaf32 commit 3a74288

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

src/main/java/net/minecraftforge/gradle/internal/ForgeGradleProblems.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ void reportUnmergedSourceSets() {
215215
.solution("Do not use the 'eclipse' plugin if you (or no one in your team) is using Eclipse.")
216216
.solution(HELP_MESSAGE));
217217
}
218+
219+
void reportMissingEclipsePlugin(String taskName) {
220+
report("eclipse-missing-for-run-generation", "Eclipse plugin is not loaded", spec -> spec
221+
.details("""
222+
The Eclipse plugin is not loaded into this build, yet it was tasked with creating Eclipse run configurations.
223+
This may cause incorrect values to be used for the Eclipse project's output directory and project name.
224+
It is highly recommended to use the 'eclipse' plugin with your project if you plan on regularly using Eclipse."""
225+
)
226+
.severity(Severity.WARNING)
227+
.solution("Use the 'eclipse' plugin in your build.")
228+
.solution("Run the '%s' task directly from Eclipse.".formatted(taskName))
229+
.solution(HELP_MESSAGE));
230+
}
218231
//endregion
219232

220233
//region Access Transformers

src/main/java/net/minecraftforge/gradle/internal/MinecraftExtensionImpl.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private void finish(Settings settings) {
155155
}
156156

157157
static abstract class ForProjectImpl extends MinecraftExtensionImpl implements ForProject {
158-
private @Nullable TaskProvider<Task> genEclipseRuns;
158+
private final TaskProvider<Task> genEclipseRuns;
159159
final DirectoryProperty eclipseOutputDir = getObjects().directoryProperty().convention(getProjectLayout().getProjectDirectory().dir("bin"));
160160

161161
// Slime Launcher
@@ -230,17 +230,16 @@ public ForProjectImpl(ForgeGradlePlugin plugin) {
230230
);
231231
}
232232

233-
getProject().getPluginManager().withPlugin("eclipse", appliedEclipsePlugin -> {
234-
var eclipse = getProject().getExtensions().getByType(EclipseModel.class);
235-
236-
this.genEclipseRuns = getProject().getTasks().register("genEclipseRuns", task -> {
237-
task.setGroup("IDE");
238-
task.setDescription("Generates the run configuration launch files for Eclipse.");
239-
});
240-
eclipse.synchronizationTasks(genEclipseRuns);
241-
242-
this.eclipseOutputDir.fileProvider(getProviders().provider(() -> eclipse.getClasspath().getDefaultOutputDir()));
233+
genEclipseRuns = getProject().getTasks().register("genEclipseRuns", task -> {
234+
task.setGroup("IDE");
235+
task.setDescription("Generates the run configuration launch files for Eclipse.");
243236
});
237+
getProject().getPluginManager().withPlugin("eclipse", appliedPlugin ->
238+
getProject().getExtensions().configure(EclipseModel.class, eclipse -> {
239+
eclipse.synchronizationTasks(genEclipseRuns);
240+
eclipseOutputDir.fileProvider(getProviders().provider(() -> eclipse.getClasspath().getDefaultOutputDir()));
241+
})
242+
);
244243

245244
// Finish when the project is evaluated
246245
getProject().afterEvaluate(this::finish);
@@ -324,15 +323,16 @@ private void finish(Project project) {
324323
sourceSet.getJava().getDestinationDirectory().set(unifiedDir);
325324
}
326325

327-
project.getPluginManager().withPlugin("eclipse", eclipsePlugin -> {
328-
var eclipse = project.getExtensions().getByType(EclipseModel.class);
329-
eclipse.synchronizationTasks(syncMavenizer);
326+
project.getPluginManager().withPlugin("eclipse", appliedPlugin ->
327+
project.getExtensions().configure(EclipseModel.class, eclipse -> eclipse.synchronizationTasks(syncMavenizer))
328+
);
329+
});
330330

331-
if (mergeSourceSets)
332-
eclipse.getClasspath().setDefaultOutputDir(sourceSetsDir.getAsFile().get());
333-
else
334-
problems.reportUnmergedSourceSets();
335-
});
331+
project.getPluginManager().withPlugin("eclipse", eclipsePlugin -> {
332+
if (mergeSourceSets)
333+
project.getExtensions().configure(EclipseModel.class, eclipse -> eclipse.getClasspath().setDefaultOutputDir(sourceSetsDir.getAsFile().get()));
334+
else
335+
problems.reportUnmergedSourceSets();
336336
});
337337

338338
for (var minecraftDependency : this.minecraftDependencies) {

src/main/java/net/minecraftforge/gradle/internal/SlimeLauncherEclipseConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ public SlimeLauncherEclipseConfiguration() {
108108

109109
@TaskAction
110110
protected void exec() {
111+
if (!this.getEclipseProjectName().isPresent())
112+
problems.reportMissingEclipsePlugin(this.getName());
113+
111114
List<String> args;
112115
List<String> jvmArgs;
113116
MapProperty<String, String> environment;

0 commit comments

Comments
 (0)