4
votes

How can I define the source folder order in my maven pom file? I am currently using the standard maven directory layout but whenever I run the command "mvn eclipse:eclipse" the source folder order is as follows:

  1. src/test/java
  2. src/test/resources
  3. src/main/java
  4. src/main/resources

How can I have it set to:

  1. src/main/java
  2. src/main/resources
  3. src/test/java
  4. src/test/resources

The class path file generated also has the test folders before the main folders.

2
Why are you using the maven-eclipse-plugin? It's been obsolete for years. - chrylis -cautiouslyoptimistic-
Order of appearance? Could you explain with more details which is your problem? - Leandro Carracedo
chrysli: I am using maven-eclipse-plugin because this is what is used at work. PatrickLC: It is really just the order of appearance. No actual problems. - StickStack

2 Answers

1
votes

This is intentional, because when running unit tests under Maven with the surefire plugin, test classes and resources come before the main classes and resources in the classpath. This allows test resources to override the main ones, for example a log4j.properties file to have different logging settings for testing than in the standard build.

Additional:

Surefire (since 2.0.8) classpath order described here: http://jira.codehaus.org/browse/MNG-3118

5
votes

To get the order you prefer, add this to your pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-eclipse-plugin</artifactId>
      <version>2.10</version><!-- correct version for you? -->
      <configuration>
        <testSourcesLast>true</testSourcesLast>
      </configuration>
    </plugin>
  </plugins>
</build>