Skip to content

Commit

Permalink
[Fix]: Fixes IDEA not detecting preRun tasks (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Jun 29, 2024
1 parent 2a8a833 commit f188fa2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskExecutionRequest> taskRequests = new ArrayList<>(startParameter.getTaskRequests());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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.
*
* <p>This can be through a project import, or a task execution.</p>
*
* @return whether this is an IntelliJ-based invocation
*/
public boolean isIdeaSyncing() {
return Boolean.getBoolean("idea.sync.active");
}

Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -261,7 +272,7 @@ private void onCommonEclipse(final BiConsumer<Project, EclipseModel> toPerform)
* @param toPerform the actions to perform
*/
public void onGradle(final GradleIdeImportAction toPerform) {
if (!isEclipseImport() && !isIdeaImport() && !isVscodeImport()) {
if (!isEclipseImport() && !isIdeaAttached() && !isVscodeImport()) {
toPerform.gradle(project);
}
}
Expand Down

0 comments on commit f188fa2

Please sign in to comment.