views:

547

answers:

5

What are the hidden features of Maven2?

A: 

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

Xymor
I'm pretty sure you don't need to edit your pom.xml for this.
lindelof
Indee, maven automatically downloads whatever plugin if name matches. However it's a good pratice to add it to the pom and specially include a specific version(which I forgot) to avoid surprises with different enviroments later on.
Xymor
dependency:tree is often a lifesaver when dealing with multiple module projects
sal
+2  A: 

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"&gt;
    <profile>
        <id>localcacheproxies</id>

        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>

        <repositories>
            <repository>
                <id>localCacheProxy</id>
                <url>http://my-local-proxy.com/maven-proxy&lt;/url&gt;
            </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)

krosenvold
+2  A: 

Take a look at dependency:analyze as well.

Brian Fox
A: 
  1. project inheritance
  2. project aggregation
  3. assembly:assembly
  4. reporting (findbugs, checkstyle, clover, pmd, etc)
dfa
A: 

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.

CaptainAwesomePants
"Maven has a cool, hidden feature called filtering (Documentation here)." Lol. It's hidden and documented.
Brian Fox
Hidden and documented are not mutually exclusive. If you don't know it exists, you wouldn't think to check the documentation for it. Thus, it can only be discovered, and what is discovered? Hidden things. It's like labeled blocks in Java. Totally documented. Largely unknown.
CaptainAwesomePants