Usage of maven Build Helper Maven Plugin
Asked Answered
C

1

14

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>
Chickie answered 24/5, 2012 at 9:40 Comment(10)
To add a source folder you should add a source folder outside the target folder. May be you can give more details what you like to achieve.Insecure
@Insecure I need to add a generated folder. Please see editsChickie
The question is what kind of generated folder from what kind of tool? Are you using some kind of generation plugin ?Insecure
@Insecure its a maven generated folder - and its path is target/sources/mygeneratedfiles The folder is generated by MavenChickie
You didn't answer the question but anyway the problem seems to be that the build-helper plugin is exectued in the wrong phase.Insecure
@Insecure the generated folder contains class files. Sorry but I dont know how to go into any more detail. The tools that generates it is Maven, by that I mean its automatically generated when I run the package goal .Chickie
What kind of Maven(-plugin) is generating that classes ? If it's generated during the package goal you can't try to run the build-helper in a phase before. That will not work. The generating of sources should be done in earlier phases.Insecure
@Insecure I'm using the default package goal lifecycle phase as described at maven.apache.org/guides/introduction/…Chickie
If you run your mvn command with -X and look at the output, does the plugin execution that generates the source files run before the build-helper-maven-plugin execution or after? If the build helper is running before the code generation that is likely the problem.Gypsum
Please check here: /m2e-lifecycle-mapping-not-foundGyrfalcon
M
14

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>
Megaphone answered 18/2, 2013 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.