Question

What are the hidden features of Maven2?

Was it helpful?

Solution

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)

OTHER TIPS

Take a look at dependency:analyze as well.

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.

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

  1. project inheritance
  2. project aggregation
  3. assembly:assembly
  4. reporting (findbugs, checkstyle, clover, pmd, etc)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top