Listen to Maven Build Events

I need to execute taks after a module / project is built with the Maven plugin. I could not find a listener that would inform me about this.

Are there listeners in Maven Plugin that can be used?

Are there IntelliJ listeners that can be used?

Thanks - Andy Schaefer

6 comments
Comment actions Permalink

Use org.jetbrains.idea.maven.importing.MavenImporter extensionPoint.

You can do the following:
1. add your MavenImporter extention, e.g.

 
<idea-plugin>
  <extensions defaultExtensionNs="org.jetbrains.idea.maven">
    <importer implementation="your.MavenImporterImpl"/>
  </extensions>
</idea-plugin>


2. implement org.jetbrains.idea.maven.importing.MavenImporter#process method
3. and add your task as an entry to List<MavenProjectsProcessorTask> postTasks parameter of the process method

0
Comment actions Permalink

Thanks for the reply. I did the follwoing:

1. Create the Maven Importer and define it in the plugin.xml:

 
<extensions defaultExtensionNs="org.jetbrains.idea.maven">
    <importer implementation="com.headwire.aem.tooling.intellij.communication.MavenListener"/>
</extensions>
 
 
public class MavenListener
    extends MavenImporter
{
    public MavenListener() {
        super("org.apache.felix", "maven-bundle-plugin");
    }

    @Override
    public void
preProcess(Module module, MavenProject mavenProject, MavenProjectChanges changes, MavenModifiableModelsProvider modifiableModelsProvider) {
        String test = "";
    }

    @Override
    public void
process(MavenModifiableModelsProvider modifiableModelsProvider, Module module, MavenRootModelAdapter rootModel, MavenProjectsTree mavenModel, MavenProject mavenProject, MavenProjectChanges changes, Map<MavenProject, String> mavenProjectToModuleName, List<MavenProjectsProcessorTask> postTasks) {
        postTasks.add(
            new MavenProjectsProcessorTask() {
                @Override
                public void
perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator) throws MavenProcessCanceledException {
                    String test = "";
                }
            }
        );
    }
}


But the process method isn't called at all. The process method is only called from the MavenModuleImporter#configFacets but when I put a breakpoint there I also see that this isn't called either.

I build the project from the Maven Plugin by running the 'install' goal. Is there anything I am missing here?

Thanks - Andy

0
Comment actions Permalink

Oops, I'm sorry, I thaught you need to hook after creation/reimporting of the IDEA project/modules by maven plugin.
Do I understand you correctly, that you want to run your task after each invocation of maven run configuration with "install" goal defined?
If yes, there is no such an API in the maven plugin.

0
Comment actions Permalink

Yes, that was the idea.

But what I need is to know when an Artifact (JAR file) has changed to display the change in my plugin. I guess I could accmplish the same thing with a VirtualFileListener to see if the artifact has changed.

Thanks for your help - Andy

0
Comment actions Permalink

By default, all files under excluded directory are not included in VFS, and maven output 'target' directory will be excluded for most of maven projects.
You can try to add maven project artifact directory to VFS and use VirtualFileListener but it can be not so easy, since the directory might not exist yet and can be created by external tool like maven CLI invocation.
Also if you add the whole 'target' directory to VFS it may slow down the performance.

0
Comment actions Permalink

I just did that and it works with excluded target (build directory) folder under IntelliJ 14 CE.

Thanks for your help - Andy

0

Please sign in to leave a comment.