Build and access jar in run configuration

Answered

I'm writing a plugin for IntelliJ.

I'm currently writing a Run Configuration that extends ModuleBasedConfiguration and I'd like to create for the selected module a jar and to access the location where the jar has been created.

Where can I find a tutorial on this topic?

 
0
6 comments
Official comment

There's builtin functionality in IntelliJ IDEA for this - Artifacts. https://www.jetbrains.com/help/idea/artifacts.html

 

In Run configuration, you can add "Build Artifacts" to "Before Launch" section of Run Configuration to trigger rebuild.

 

Ok, and how can I do it in Java when I create the  run configuration?

0

Please see com.intellij.packaging.artifacts.ArtifactManager & com.intellij.execution.RunManagerEx#setBeforeRunTasks(com.intellij.execution.configurations.RunConfiguration, java.util.List<com.intellij.execution.BeforeRunTask>)

0

Ok, my run configuration extends

ModuleBasedConfiguration

In the constructor I get the list of Before Run configs using

List<BeforeRunTask<?>> beforeRunTasks = new ArrayList<>(getBeforeRunTasks());


and I add mine into that list. Then always in the constructor I do:

final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
runManager.setBeforeRunTasks(this, beforeRunTasks);


However, for such a reason I don't get, later on RunManagerImpl calls readBeforeRunTasks and my task disappear.
I miss something, but I'm struggling to understand what exactly.

Any hint?

0

Please see com.intellij.packaging.impl.run.BuildArtifactsBeforeRunTaskProvider#setBuildArtifactBeforeRun

0

Thanks, problem solved

0

Please sign in to leave a comment.