-
Notifications
You must be signed in to change notification settings - Fork 0
Migration
This page lists some usage patterns of Maven 3 which have changed in Maven 4.
The Maven 3 elements are deprecated and should be replaced by the new <sources> element introduced in Maven 4.
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
</build><build>
<sources>
<source>
<directory>src/main/java</directory>
</source>
<source>
<scope>test</scope>
<directory>src/test/java</directory>
</source>
</sources>
<build>Note that the declaration of a <sources> element replaces the default values,
hence the need to declare the source and test directories together.
The new <source> element allows more flexibility such as specifying many directories,
the include/exclude filters, the targeted Java release and more.
The external plugin used in Maven 3 is no longer needed
and should be replaced by the build-in <sources> elements.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-directory</id>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/extension/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build><build>
<sources>
<source>
<directory>src/main/java</directory>
</source>
<source>
<directory>src/extension/java</directory>
</source>
<source>
<scope>test</scope>
<directory>src/test/java</directory>
</source>
</sources>
<build>Reminder: because <sources> replaces the default values, these defaults need to be explicitly specified.
The Maven 3 way to declare include/exclude filters is still supported,
but should be replaced by the <sources> element when applicable.
Those two ways are not strictly equivalent:
- The Maven 4 way specifies filters independently for each source directory. These filters will be applied by all plugins that migrated to the Maven 4 API, not only the compiler plugin.
- Conversely, the Maven 3 way specifies filters which will be applied only by the compiler plugin. However, these filters apply to all source directories.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/Foo*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build><build>
<sources>
<source>
<directory>src/main/java</directory>
<excludes>
<exclude>**/Foo*.java</exclude>
</excludes>
</source>
<source>
<scope>test</scope>
<directory>src/test/java</directory>
</source>
</sources>
</build>