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

  • SEARCH
  • Home
  • 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 6921235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:15:01+00:00 2026-05-27T10:15:01+00:00

I already have my pom.xml set up to do some basic replacing on a

  • 0

I already have my pom.xml set up to do some basic replacing on a file during the prepare-package phase:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>maven-replacer-plugin</artifactId>
    <version>1.3.8</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>replace</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <file>target/classes/plugin.yml</file>
        <replacements>
            <replacement>
                <token>maven-version-number</token>
                <value>${project.version}-${project.build.number}</value>
            </replacement>
        </replacements>
    </configuration>
</plugin>

However, I’d like to have that value be conditional on whether a particular environment variable is set. I run builds through Jenkins, and so I’d like to check if the environment variable BUILD_NUMBER is set; if so, it should take the place of project.build.number.

Is there any convenient way to do that within the replacer plugin? I read over the usage guide, and couldn’t find anything immediately useful.

  • 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-27T10:15:02+00:00Added an answer on May 27, 2026 at 10:15 am

    You can use profiles to do this.

    Use something like the following properties:

    <properties>    
        <!-- The default build number if the env var is not set -->
        <build.number.to.use>0</build.number.to.use>
    </properties>
    

    Define your replacer plugin plugin to use ${build.number.to.use}:

    ...
    <configuration>
        <file>target/classes/plugin.yml</file>
        <replacements>
            <replacement>
                <token>maven-version-number</token>
                <value>${project.version}-${build.number.to.use}</value>
            </replacement>
        </replacements>
    </configuration>
    ...
    

    And define the profile that is activated when the environment variable is set:

    <profiles>
        <profile>
            <id>build-number-is-set</id>
            <activation>
              <property>
                <name>env.BUILD_NUMBER</name>
              </property>
            </activation>
            <properties>
                <build.number.to.use>${env.BUILD_NUMBER}</build.number.to.use>
            </properties>
        </profile>
    </profiles>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have integrated Cargo plugin in my maven 2 project POM.xml. During hot deployment
I already have an enterprise Java EE application. I want expose some of the
I already have a project with a .pro file that can be built in
I have a maven POM file for a web service. For one of the
I have a maven pom build file in the root directory of my project.
I already have defined the following condition in .htaccess file: RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif)$ RewriteRule
I already have some simple project with one migration script: # --- !Ups create
I installed m2eclipse plugin. I want to create pom.xml in my project which is
I already have MSVC++ 2010 Express installed, and my vcvarsall.bat file is at C:\Program
Is it possible to set environment variable with maven (OS: Linux)? I already have

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.