In the previous section, we showed you how to create a profile
that overrides default behavior for a specific target
environment. In the previous build, the default build was designed for
development, and the
profile exists to provide configuration for a production environment.
What happens when you need to provide customizations based on
variables such as operating systems or JDK version?
Maven provides a way to “activate” a profile for different
environmental parameters. This is called profile activation.
Take the following example. Assume we have a Java library that has a specific feature available only in the Java 6 release—the Scripting Engine as defined in JSR-223 (see http://jcp.org/en/jsr/detail?id=223). You’ve separated the portion of the library that deals with the scripting library into a separate Maven project, and you want people running Java 5 to be able to build the project without attempting to build the Java 6 specific library extension. You can do this by using a Maven profile that adds the script extension module to the build only when the build is running within a Java 6 JDK. First, let’s take a look at our project’s directory layout and how we want developers to build the system.
When someone runs mvn install
with a Java 6 JDK, you want the build to include
simple-script project’s build;
when they are running in Java 5, you would like to skip the
simple-script project build. If you failed
to skip the
simple-script project build ...