DEV Community

Maxime Guilbert
Maxime Guilbert

Posted on

Define default local maven properties

Working with pipelines which are abstract from the projects and environments can be really useful, but for the dev, it can be really annoying.

In a context of a maven project, all the variables added with -D parameters should be added by the dev to his commands right?

No!

With Maven projects, there are 2 ways to counter that.


For our solutions, we will take the following **pom.xml* part to understand what we should do.*

<project>
  ...
  <properties>
    <mavenVersion>3.0</mavenVersion>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-artifact</artifactId>
      <version>${mavenVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-core</artifactId>
      <version>${mavenVersion}</version>
    </dependency>
  </dependencies>
  ...
</project>
Enter fullscreen mode Exit fullscreen mode

Default value in the pom

In the previous example, we can define a property "mavenVersion" which can contain our default value.

...
  <properties>
    <mavenVersion>2.10.5</mavenVersion>
  </properties>
...
Enter fullscreen mode Exit fullscreen mode

In this case we need to know that if the same parameter is defined in the command line, the value in the command line will override this one!

So you can keep something in your pom.xml file without any issue.


Default value in the settings.xml

In the case where you can't keep the value in the pom.xml file, or if you have the same required parameter for a lot of projects, you can set it in your settings.xml file!

...
<profiles>
    <profile>
      <id>my-profile</id>
      <properties>
        <mavenVersion>2.10.5</mavenVersion>
      </properties>
      ...
    </profile>
</profiles>
...
Enter fullscreen mode Exit fullscreen mode

Restart your IDE, refresh your maven configs, and everything should be fine!

I hope it will help you! 🍺

Discussion (0)