Maven: Why adding a test source through the build assistant does not work when creating an eclipse project?

Our maven pom.xml indicates the addition of an additional source and test source folder if a specific profile is activated (here "java8"). The corresponding pom part is as follows

    <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 looks like the right specification.

Launch mvm install -P java8I see that additional tests run as expected.

However, at startup, the mvm eclipse:eclipse -P java8additional folder of the original test source does not appear in eclipse .classpath.

: maven eclipse? ?

+4
4

, , (, ):

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

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

eclipse.classpath( ). "add-test-source" .

, :

    <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>

" ". http://mojo.codehaus.org/build-helper-maven-plugin/usage.html

+4

, , .

mvn install -P java8 install. , maven install, generate-test-sources test... install. generate-test-sources, , .

mvn eclipse:eclipse -P java8, ( , eclipse eclipse), (). eclipse generate-resources. , generate-resources "include" generate-test-sources (. ), .

, Eclipse java8. ( ) - , Maven, Active Maven java8 → OK. " " → " JUnit" ( - , ). , Eclipse (Kepler 4.3.1 ), m2e, m2e.

+1

, , , , add-test-source generate-sources generate-test-sources.

, mvn eclipse:eclipse , . , generate-sources, doco (http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html):

Invokes the execution of the lifecycle phase generate-resources prior to executing itself.

, generate-test-sources , . , maven , (http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html), run generate-sources AND generate-test-sources, . , , ( ):

mvn generate-test-sources eclipse:eclipse

... , . , build-helper-maven-plugin , , maven-eclipse-plugin .

, AFAIK ( ), .

() build-helper-maven-plugin maven-eclipse-plugin ( , POM ) generate-test-sources, mvn eclipse:eclipse, :

mvn generate-test-sources

, POM, :

<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>
                            <directory>src/test/java8</directory>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <executions>
                <execution>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>eclipse</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

, , mvn eclipse:eclipse , . , maven-eclipse-plugin , generate-test-sources (.. mvn clean install), , , , , , (, clean) .

+1

eclipse: eclipse, http://www.eclipse.org/m2e/ maven pom.xml.

maven m2e maven plugin, maven . - pom.xml:

<pluginManagement>
  <plugins>
    <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-test-source</goal>
               </goals>
               </pluginExecutionFilter>
               <action>
                 <execute>
                   <runOnIncremental>true</runOnIncremental>
                 </execute>
               </action>
            </pluginExecution>
         </pluginExecutions>
       </lifecycleMappingMetadata>
     </configuration>
    </plugin>
  </plugins>
</pluginManagement>  

!

, m2e maven.

+1

All Articles