Compile task is not triggering
Answered
I have created an CompileTask extension in my project. It is registered as an extension in the project plugin.xml (and the plug icon appears in the IDE). However, the execute method is never triggered. I have tried many different things (adding/removing extensionPoints dependencies, adding/removing id and order, among them), but nothing works. What am I missing? It's probably obvious, but I just can't see it. Any help is appreciated.
<!--
~ Copyright (c) Todd Heidenthal 2023.
-->
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<!-- Unique identifier of the plugin. It should be FQN. It cannot be changed between the plugin versions. -->
<id>heidenthal.idea.plugin.MyFirstPlugin</id>
<!-- Public plugin name should be written in Title Case.
Guidelines: https://plugins.jetbrains.com/docs/marketplace/plugin-overview-page.html#plugin-name -->
<name>Create a clever name</name>
<version>2023.12.15</version>
<!-- A displayed Vendor name or Organization ID displayed on the Plugins Page. -->
<vendor url="https://github.com/heidenthal/">
Todd Heidenthal
</vendor>
<!-- Description of the plugin displayed on the Plugin Page and IDE Plugin Manager.
Simple HTML elements (text formatting, paragraphs, and lists) can be added
inside of <![CDATA[ ]]> tag.
Guidelines: https://plugins.jetbrains.com/docs/marketplace/plugin-overview-page.html#plugin-description -->
<description>
<![CDATA[Write something here]]>
</description>
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<!-- TODO: Figure out how to determine earliest version -->
<!-- <idea-version since-build="212.4746.92"/>-->
<!-- <idea-version since-build="213.5744.223"/>-->
<!-- Product and plugin compatibility requirements.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html -->
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.java</depends>
<depends>com.intellij.modules.lang</depends>
<!-- <extensionPoints>com.intellij.build.events.BuildEvent</extensionPoints>-->
<!-- <extensionPoints>com.intellij.build.events.Failure</extensionPoints>-->
<!-- <extensionPoints>com.intellij.openapi.compiler.CompilerTask</extensionPoints>-->
<!-- Extension points defined by the plugin.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
<extensions defaultExtensionNs="com.intellij">
<!-- on compile request -->
error.compile.ProjectCompileTask"-->
<compiler.task execute="BEFORE"
implementation="com.heidenthal.compile.ProjectCompileTask"/>
</extensions>
</idea-plugin>
public class ProjectCompileTask implements CompileTask {
@Override
public boolean execute(@NonNull final CompileContext compileContext) {
boolean result = true;
if (!compileContext.isAutomake()) {
final Project project = compileContext.getProject();
final boolean allowBuildToContinue = allowBuildToContinue(project);
if (!allowBuildToContinue) {
return false;
}
final AnalysisState analysisState = project.getService(AnalysisState.class);
if (!analysisState.hasCompleted()) {
if (!new ContinueWithoutWaitingDialog(project).showAndGet()) {
return true;
}
try {
analysisState.await();
} catch (final InterruptedException exception) {
new ProcessInterruptedDialog(project).show();
return allowBuildToContinue(project);
}
}
DumbService.getInstance(project).runWhenSmart(() -> {
// Analyze the project
final ProjectAnalyzer projectAnalyzer = ProjectAnalyzer.getInstance(project);
ProgressManager.getInstance().run(projectAnalyzer);
});
try {
analysisState.await();
} catch (final InterruptedException exception) {
new ProcessInterruptedDialog(project).show();
} finally {
result = allowBuildToContinue(project);
}
}
return result;
}
}
Please sign in to leave a comment.
Solved: I have no idea what is different, but this morning when I tried again after clearing out all project related data from the IntelliJ installation, this started working. Must have been some bad file stored during the prior build process. Weird
NOT Solved: I retract that solved statement. This only works for some projects. The compile task invokes for the intellij-community project, but not for my own small test project. I am baffled
SOLVED (Really): This was a matter of project defaults and user error. My small project was set to build using Gradle, which is the default when creating a new Gradle-based project. However, for the compile plugin to execute, the project must be set to build with IntelliJ IDEA