What are the hidden features of Maven2?
With maven-dependency-plugin it's possible to resolve dependency conflicts and cyclic dependency problems.
Add to your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
Then run mvn dependency:resolve or mvn dependency:build-classpath to test it.
More about the dependency plugin: http://maven.apache.org/plugins/maven-dependency-plugin/howto.html
You can use the settings.xml to force ALL maven builds running on your local machine to also use a locally installed maven proxy. Saving yourself and the network time.
<settings xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profile>
<id>localcacheproxies</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>localCacheProxy</id>
<url>http://my-local-proxy.com/maven-proxy</url>
</repository>
</repositories>
</profile>
</profiles>
Note that the namespace headings in this settings.xml also gives a decent intellisense as opposed to other examples posted here. (create in your home directory .m2 folder on windows, linux and mac and all os'es)
- project inheritance
- project aggregation
- assembly:assembly
- reporting (findbugs, checkstyle, clover, pmd, etc)
Sometimes you have a file that needs to contain some value that can only be discovered at build time. Maybe you have a Java class that checks to see if the evaluation period is up, and you define that period as "thirty days after this build was compiled". You need a way to inject the current date, or some other property, directly into the build.
Maven has a cool, hidden feature called filtering (Documentation here). With filtering, you can ask Maven to look for patterns in certain source files and replace them with some value, and it's as easy to activate as this:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
What can you stick into the filter? Any environment variable, most of the values in the pom file, and information about the java compiler. Now If you change your version number in Maven, you don't have to go find your whatever.properties file and update your version there, too. You can just modify it in Maven and you're done.