Search code examples
javaeclipsemavenmaven-pluginbuild-helper-maven-plugin

build-helper-maven-plugin adding additional source


I am trying to add an additional source folder to my current maven project by using build-helper-maven plugin.

This source folder contains some common classes, like utility classes.

For that, here is my relevant pom.xml

 <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
      <execution>
        <id>add-source</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>add-source</goal> 
        </goals>
        <configuration>
          <sources>
             <source>C:/Users/CommonIncludes/src</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>

Eclipse is showing the following error :

Build path entry is missing. Project->Right Click->Java build path->Source->

Project/Users/CommonIncludes/src(missing)

Here the additional source location : "C:/Users/CommonIncludes/src" is outside of the workspace of the current project. But eclipse always treating this as a location from current project.

I am using Eclipse 4.3 and m2e. How can I overcome this error through MAVEN, so that Eclipse can identify the linked source from correct location.? Or is there any alternate way to do this using MAVEN?

Any help will be greatly appreciated. Thanks in advance.


Solution

  • Found it in an alternate way..works great.!

    Steps include

    1. Removed build-helper-maven-plugin from pom .

    2. Created another maven project and added the common classes in it. Added maven-source-plugin in this pom to generate sources.

    3. To the same pom, added maven-dependency-plugin to copy this generated sources to the desired location (My project's src/main/java).

    4. Run a maven build for common classes project.

    Now the common code in my project. Thanks.