You can, but it depends on what you need it for. This is the most common way of doing it:
<profiles>
<profile>
<id>profile-1</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
<configuration>
<properties>
<my-prop>Yabadabadoo!</my-prop>
</properties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
but this only sets the system property during Maven's execution, so if you want (for instance) this class to pick it up:
package org.example;
public class App {
public static void main( String[] args) {
System.out.println("-->" + System.getProperty("my-prop"));
}
}
you need to run it with mvn -P profile-1 compile exec:java -Dexec.mainClass=org.example.App
and it will yield the following result:
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ sys-prop ---
-->Yabadabadoo!
Running it without the compile
goal will give you a null
because the exec
plugin is not bound to any build phase in this instance.
But if you need system properties for (say) unit tests, then the surefire
plugin is what you need instead.