Using optional options

Using optional options

Unknown macro: {scrollbar}

There might be cases when you have to use certain options only under specific conditions as for example you would like to enable debugging only when you set a system property. In order to fulfill such an requirement you can use optional composite option as in the following example:

@Configuration
public static Option[] configure()
{
    return options(
        when( Boolean.getBoolean( "isDebugEnabled" ) ).useOptions(
            vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" ),
            timeout( 0 )
        )
    );
}

In the above example the vmOption and timeout options will be included only when there is a system property named 'isDebugEnabled' with a value of 'true'.

If you are using Maven you can then use the following to switch the debug options on:

mvn install -DisDebugEnabled=true

The condition is not limited to just system properties. You can use any expression that evaluates to a boolean or define your own condition.