How do I start Maven “compile” goal on save in Eclipse?

岁酱吖の 提交于 2019-11-27 11:29:14

In the project preferences it is possible to configure a lifecycle mapping. But for some reason I can only add custom goals to "after clean" and "on resource changed". When I add the "compile" goal to the "resource changed" lifecycle mapping, then the JavaScript files are compiled when I change a resource. So I could put my JavaScript files into the resources folder instead and it would work but this sounds pretty ugly.

As you've noticed, the default goals run on incremental builds in Eclipse are process-resources and resources:testResources. Personally, I don't find ugly to put js file under resources and I would just bind the javascript plugin on process-resources.

It is also working when I tell Eclipse to "clean" my project. Then the compile goal target is called.

On full build (after a clean from Eclipse), goals run are process-test-resources which is actually a build lifecycle phase that includes the compile phase, that's why compile get called when you clean your project from Eclipse. But this doesn't solve your issue (running your plugin on save).


As I said, I would just put the js file under resources. But there is maybe another option: adding another Builder to the project. Right-click on your project, then Properties > Builders > New > Maven Build and define your plugin goal as goal to run during Auto Build Goals (change or remove the other goals to suit your needs):

alt text http://img694.imageshack.us/img694/2382/screenshot003wo.png

But I prefer the other approach.

childno͡.de

since @pascal-thivent answer is outdated (as mentioned in the comments) and hinted by @akostadinov https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html :

You have to add a valid maven lifecycle action

Example for a jar which is automatically deployed locally by maven install plugin:

<build>
    <!-- ... -->

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>

                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-jar-plugin</artifactId>
                                    <versionRange>[2.0,)</versionRange>
                                    <goals>
                                        <goal>jar</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute>
                                        <runOnConfiguration>true</runOnConfiguration>
                                        <runOnIncremental>true</runOnIncremental>
                                    </execute>
                                </action>
                            </pluginExecution>

                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-install-plugin</artifactId>
                                    <versionRange>[2.5.0,)</versionRange>
                                    <goals>
                                        <goal>install</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute>
                                        <runOnConfiguration>true</runOnConfiguration>
                                        <runOnIncremental>true</runOnIncremental>
                                    </execute>
                                </action>
                            </pluginExecution>

                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Hint: relates to Maven Project Builder is invoked every time I change a source file (GWT) and as a warning: install typically includes tests if you have included them in your normal maven build cycle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!