Build artifact from a directory after poststartupactivity
I am trying to build a plugin where the project artifact is built as soon as a project is imported and startupactivity is completed.
I cannot figure out how to call artifact build in IntelliJ from my class.
Please sign in to leave a comment.
You can use ProjectTaskManager#build(Artifact[]) for that.
There does not seem to be any class like ProjectTaskManager. Can you please help me with a sample code snippet?
The full name of class is com.intellij.task.ProjectTaskManager. If you don't have such a class, it means that your plugin project isn't configured properly. How did you set it up? Do you write it using gradle-intellij-plugin?
No. I selected File -> New -> Project -> IntelliJ Platform Plugin. Then I set up the SDK as in the SDK set up guide.
My IntelliJ version is 141.1010 and I am using JDK 1.6 along with it.
The package com.intellij.task does not show.
141.* is IntelliJ IDEA 14.1 version which was released 3 years ago. It indeed doesn't have this class. Do you really need to develop a plugin for such an old version?
Yes. It has to be compatible with 141* versions. When was this class introduced? Is there any way I can develop a plugin on a higher version where this class is available and have some kind of backward compatibility?
For now, I'll develop the plugin in one of the higher versions where this class is available. Can you help me with a sample code snippet? What to pass to the artifact object? How do I pass my artifact.xml to ProjectTaskManager.build(Artifact[])?
In order to get an Aritfact instance you can use ArtifactManager.getInstance(project).findArtifact(name) method.
ProjectTaskManager was introduced in IntelliJ IDEA 2016.3. If you want to make your plugin compatible with older versions of IDEA, you can use com.intellij.openapi.compiler.CompilerManager#make(CompileScope, CompileStatusNotification) method instead and pass com.intellij.packaging.impl.compiler.ArtifactCompileScope#createArtifactsScope(Project, Collection<Artifact>) into it.
I tried using ArtifactManager.getInstance(project).findArtifact(artifactName.xml) to get the artifact object. However, this returns null.
Note that `findArtifact` expects artifact name as it shown in UI, not the name of xml file. You can also call ArtifactManager.getInstance(project).getArtifacts() to enumerate all the artifacts.