Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of maven Build Helper Maven Plugin

Tags:

maven

m2e

I'm attempting to add a source folder for maven java project to Eclipse using a maven plugin.

When trying to use the org.codehaus.mojo plugin I receive the following error

Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.7:add-source (default-cli) on project application-framework: The parameters 'sources' for goal org.codehaus.mojo:build-helper-maven-plugin:1.7:add-source are missing or invalid -> [Help 1]

From reading the docs on http://mojo.codehaus.org/build-helper-maven-plugin/usage.html this should be correct ? The folder target/sources/mygeneratedfiles on exists.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
         <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>target/sources/mygeneratedfiles</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
like image 534
blue-sky Avatar asked May 24 '12 09:05

blue-sky


People also ask

What is the use of build Helper Maven plugin?

This can be used to keep track of what version of Maven was used to build a particular artifact. For example, the following POM sets the property and then uses the property to save the Maven version to the project JAR's manifest.

What is Maven helper?

A must have plugin for working with Maven. easy way for analyzing and excluding conflicting dependencies. actions to run/debug maven goals for a module that contains the current file or on the root module. action to open terminal at the current maven module path. actions to run/debug the current test file.

What is the use of Org Codehaus Mojo plugin?

This is the Mojo's Maven plugin for Cobertura. Cobertura is a free Java tool that calculates the percentage of code accessed by tests. It can be used to identify which parts of your Java program are lacking test coverage.

What is the goal for Maven build?

When Maven starts building a project, it steps through a defined sequence of phases and executes goals, which are registered with each phase. A goal represents a specific task which contributes to the building and managing of a project. It may be bound to zero or more build phases.


1 Answers

The problem is that the build helper plugin is in general too old to be used with the newest maven versions (in combination with the m2e eclipse plugin), because of the "relative new" Lifecycle-mapping rules.

I solved this issue by adding a lifecyclemapping configuration for the build-helper-maven-plugin for the orgeclipse.m2e plugib. see below:

        <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
                <lifecycleMappingMetadata>
                    <pluginExecutions>
                        <pluginExecution>
                            <pluginExecutionFilter>
                                <groupId>org.codehaus.mojo</groupId>
                                <artifactId>build-helper-maven-plugin</artifactId>
                                <versionRange>[1.0,)</versionRange>
                                <goals>
                                    <goal>add-source</goal>
                                    <goal>add-test-source</goal>
                                    <goal>add-resource</goal>
                                    <goal>add-test-resource</goal>
                                    <goal>maven-version</goal>
                                    <goal>parse-version</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <execute>
                                    <runOnConfiguration>true</runOnConfiguration>
                                    <runOnIncremental>true</runOnIncremental>
                                </execute>
                            </action>
                        </pluginExecution>
                    </pluginExecutions>
                </lifecycleMappingMetadata>
            </configuration>
        </plugin>
like image 195
Hannes Kogler Avatar answered Sep 22 '22 09:09

Hannes Kogler