From f188fa23bd3080319521a5a1450131d9ef9fea86 Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Sat, 29 Jun 2024 09:04:55 +0200 Subject: [PATCH] [Fix]: Fixes IDEA not detecting preRun tasks (#221) --- .../gradle/common/CommonProjectPlugin.java | 3 +++ .../extensions/IdeManagementExtension.java | 21 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 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 c3c9a3cb5..813e0a7ba 100644 --- a/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java +++ b/common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java @@ -273,6 +273,9 @@ private void configureIDEAIDEConventions(Project project, IDE ideConventions) { if (ideaConventions.getShouldUsePostSyncTask().get()) return; + if (!ideManagementExtension.isIdeaSyncing()) + return; + final StartParameter startParameter = innerProject.getGradle().getStartParameter(); final List taskRequests = new ArrayList<>(startParameter.getTaskRequests()); diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java index 48de350fe..77066793f 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/IdeManagementExtension.java @@ -50,7 +50,7 @@ public IdeManagementExtension(Project project) { // IntelliJ remembers to run the task post-sync even if the import fails. That will cause // situations where import errors (i.e. dependency resolution errors) will be masked by // the failed idePostSync task, since it was never created in that particular import. - if (isIdeaImport()) { + if (isIdeaAttached() && isIdeaSyncing()) { getOrCreateIdeImportTask(); } } @@ -62,7 +62,18 @@ public IdeManagementExtension(Project project) { * * @return whether this is an IntelliJ-based invocation */ - public boolean isIdeaImport() { + public boolean isIdeaAttached() { + return Boolean.getBoolean("idea.active"); + } + + /** + * Get whether Gradle is being invoked through IntelliJ IDEA. + * + *

This can be through a project import, or a task execution.

+ * + * @return whether this is an IntelliJ-based invocation + */ + public boolean isIdeaSyncing() { return Boolean.getBoolean("idea.sync.active"); } @@ -105,7 +116,7 @@ public static boolean isVscodePluginImport(final Project project) * @return {@code true} if an IDE import is ongoing, {@code false} otherwise */ public boolean isIdeImportInProgress() { - return isIdeaImport() || isEclipseImport() || isVscodeImport(); + return isIdeaAttached() || isEclipseImport() || isVscodeImport(); } /** @@ -191,7 +202,7 @@ public void apply(final IdeImportAction toPerform) { public void onIdea(final IdeaIdeImportAction toPerform) { //When the IDEA plugin is available, configure it project.getPlugins().withType(IdeaExtPlugin.class, plugin -> { - if (!isIdeaImport()) { + if (!isIdeaAttached()) { //No IDEA import even though the plugin is available, so don't configure it. return; } @@ -261,7 +272,7 @@ private void onCommonEclipse(final BiConsumer toPerform) * @param toPerform the actions to perform */ public void onGradle(final GradleIdeImportAction toPerform) { - if (!isEclipseImport() && !isIdeaImport() && !isVscodeImport()) { + if (!isEclipseImport() && !isIdeaAttached() && !isVscodeImport()) { toPerform.gradle(project); } }