Home / Java Patterns and Pitfalls     frequal.com

Maven Profiles Make Prod Builds Easy

Maven profiles let you change build parameters from the command line. For example, if you've set up a build profile called "prod", you can use this command to run a clean build with prod profile enabled:
mvn clean install -P prod

Detailed Example

Say, for example, you're creating a Flavour Web App and you want your production build to enable minification. However, for normal builds you want to leave minification off (false) to increase debuggability and legibility of stack traces. You could add these sections to your pom.xml:
  <properties>
    <minify>false</minify>
  </properties>

  <profiles>
    <profile>
      <id>prod</id>
      <properties>
        <minify>true</minify>
      </properties>
    </profile>
  </profiles>

          <!-- In teavm-maven-plugin's execution element -->
            <configuration>
              <minifying>${minify}</minifying>
            </configuration>
Now when you are developing, you can build normally, and the full function names will be in the generated code.
# Normal build, defaults to minify = false
mvn clean install
When it's time to build a prod release, simply enable the prod profile, and minification will be turned on, for a smaller (and harder to reverse-engineer) build ready for deployment in production.
mvn clean install -P prod

Last modified on 30 Sep 2024 by AO

Copyright © 2024 Andrew Oliver