O'Reilly logo

Apache Maven Cookbook by Raghuram Bharathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using properties in Maven

Maven allows us to define as well as use properties. Properties allow us to avoid hardcoding values in multiple places such as versions of dependencies. They also provide flexibility to the build tool by allowing values to be passed at runtime.

How to do it...

Let's define and use Maven properties by performing the following steps:

  1. Open the pom file of a project that we created earlier.
  2. Define a property:
    <properties>
        <junit.version>3.8.1</junit.version>
    </properties>
  3. Use the property:
    <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>${junit.version}</version>
          <scope>test</scope>
        </dependency>

How it works...

There are different types of properties. They are as follows:

  • Environment variables: Prefixing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required