Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

In this short tutorial, we’ll look at how we can pass arguments to Maven using the command line.

2. Maven Properties 

Maven properties are value placeholders. First, we need to define them under the properties tag in our pom.xml file:

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <start-class>com.example.Application</start-class>
    <commons.version>2.5</commons.version>
</properties>

Then, we can use them inside other tags. For example, in this case, we’ll use the “commons.version” value in our commons-io dependency:

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.16.1</version>
</dependency>

In fact, we can use these properties anywhere in the pom.xml, such as in the build, package, or plugin sections.

3. Define Placeholders for Properties

Sometimes, we don’t know a property value at development time. In this case, we can leave a placeholder instead of a value using the syntax ${some_property}, and Maven will override the placeholder value at runtime. Let’s set a placeholder for COMMON_VERSION_CMD:

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <commons.version>2.5</commons.version>
    <version>${COMMON_VERSION_CMD}</version>
</properties>

4. Passing an Argument to Maven

Now, let’s run Maven from our terminal as we usually do, with the package command, for example. But in this case, let’s also add the notation -D followed by a property name:

mvn package -DCOMMON_VERSION_CMD=2.5

Maven will use the value (2.5) passed as an argument to replace the COMMON_VERSION_CMD property set in our pom.xml. This is not limited to the package command — we can pass arguments together with any Maven command, such as install, test, or build.

5. Conclusion

In this article, we looked at how to pass parameters to Maven from the command line. By using this approach, instead of modifying the pom.xml or any static configuration, we can provide properties dynamically.

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW