Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6777067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:06:14+00:00 2026-05-26T16:06:14+00:00

I have my build set-up so that I pass in my variable via the

  • 0

I have my build set-up so that I pass in my variable via the command line:

mvn clean install -DsomeVariable=data

In my pom I have:

<someTag>${someVariable}</someTag>

This works fine, but I would like to identify if someVariable is not specified on the command line, and then default it so that my script can continue.

Can this be done in Maven?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:06:14+00:00Added an answer on May 26, 2026 at 4:06 pm

    You can specify default property value in the properties section of your POM file:

    <properties>
      <someVariable>myVariable</someVariable>
    </properties>
    

    If you want to make sure that the property value is ALWAYS supplied on a command line, then you can use maven-enforcer-plugin.

    Here is a link that shows how to enforce system property presence -> http://maven.apache.org/enforcer/enforcer-rules/requireProperty.html

    I’ll just copy the XML verbatim here in case the above link goes bad.

    <project>
      [...]
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>1.0.1</version>
            <executions>
              <execution>
                <id>enforce-property</id>
                <goals>
                  <goal>enforce</goal>
                </goals>
                <configuration>
                  <rules>
                    <requireProperty>
                      <property>basedir</property>
                      <message>You must have a basedir!</message>
                      <regex>\d</regex>
                      <regexMessage>You must have a digit in your baseDir!</regexMessage>
                    </requireProperty>
                    <requireProperty>
                      <property>project.version</property>
                      <message>"Project version must be specified."</message>
                      <regex>(\d|-SNAPSHOT)$</regex>
                      <regexMessage>"Project version must end in a number or -SNAPSHOT."</regexMessage>
                    </requireProperty>
                  </rules>
                  <fail>true</fail>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      [...]
    </project>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a TFS build definition set up where we pass the following extra
I have a big Maven multi-module build set up in my Jenkins. It is
I am having the following problem: a) I have a UNIX build environment set
I have an image in a C# WPF app whose build action is set
My project is ARC enabled (the build settings have Objective-C Reference Counting set to
I have to set a few projects in our VS 2005 solution to build
I have a set of source folders. I use a Java class to build
Do you have some predefined set of targets which all build.xml files you create
As part of our web application's build process, I have set up our XSLT
I have an if statement that's condition is passed to this implementation file via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.