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>
Betlista
  • 10,327
  • 13
  • 69
  • 110
blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • 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. – khmarbaise May 24 '12 at 09:43
  • @khmarbaise I need to add a generated folder. Please see edits – blue-sky May 24 '12 at 09:56
  • The question is what kind of generated folder from what kind of tool? Are you using some kind of generation plugin ? – khmarbaise May 24 '12 at 10:03
  • @khmarbaise its a maven generated folder - and its path is target/sources/mygeneratedfiles The folder is generated by Maven – blue-sky May 24 '12 at 10:07
  • You didn't answer the question but anyway the problem seems to be that the build-helper plugin is exectued in the wrong phase. – khmarbaise May 24 '12 at 10:28
  • @khmarbaise 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 . – blue-sky May 24 '12 at 10:31
  • 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. – khmarbaise May 24 '12 at 10:55
  • @khmarbaise I'm using the default package goal lifecycle phase as described at http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html – blue-sky May 24 '12 at 11:08
  • 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. – user944849 May 24 '12 at 12:30
  • Please check here: [/m2e-lifecycle-mapping-not-found](http://stackoverflow.com/questions/7409823/m2e-lifecycle-mapping-not-found?answertab=active#tab-top) – André Valadas Feb 26 '16 at 12:50

1 Answers1

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>
Hannes Kogler
  • 469
  • 6
  • 12