Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: Why does adding test source via build helper not work when generating eclipse project?

Our maven pom.xml specifies to add an additional source and test-source folder if a certain profile (here "java8") is activated. The corresponding part of the pom looks like the following

    <profile>
        <id>java8</id>
        ....
        <build>
            <plugins>
                ....
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.8</version>
                    <executions>
                        <execution>
                            <id>add-test-source</id>
                            <phase>generate-test-sources</phase>
                            <goals><goal>add-test-source</goal></goals>
                            <configuration>
                                <sources>
                                    <source>src/test/java8</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

According to http://mojo.codehaus.org/build-helper-maven-plugin/usage.html this appears to be the correct specification.

Running mvm install -P java8 I see that the additional tests are performed as expected.

However, running mvm eclipse:eclipse -P java8 the additional test source folder does not appear in eclipse .classpath.

Question: How do I have to configure maven to add the test source folder to the eclipse configuration? Is the above behavior a bug or a misconfiguration?

like image 567
Christian Fries Avatar asked Feb 15 '23 19:02

Christian Fries


1 Answers

Having spent some time experimenting with this, I can give a partial answer to my own question (hopefully saving some time of other developers):

If one uses

                            <phase>generate-sources</phase>
                            <goals><goal>add-test-source</goal></goals>

instead of

                            <phase>generate-test-sources</phase>
                            <goals><goal>add-test-source</goal></goals>

then the test source folder is added to the eclipse .classpath (and it is added as a test folder). I.e. I am executing "add-test-source" in a different phase now.

In other words the profile looks like this:

    <profile>
        <id>java8</id>
        ....
        <build>
            <plugins>
                ....
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.8</version>
                    <executions>
                        <execution>
                            <id>add-test-source</id>
                            <phase>generate-sources</phase>
                            <goals><goal>add-test-source</goal></goals>
                            <configuration>
                                <sources>
                                    <source>src/test/java8</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

This looks like a "workaround". It still contradicts the specification on http://mojo.codehaus.org/build-helper-maven-plugin/usage.html

like image 100
Christian Fries Avatar answered Feb 17 '23 10:02

Christian Fries