Settings JVMargs per instance type

So I was setting up my devops and realized that I had a defauklt set of JVMArgs.

But I realized that those would need to be changed per ‘instance’ in clouds environments (ie nano/medium/large) and to have a ‘default’ if no instance is set.

So I thought I would post here how I resolved this.

Basically in my ‘’ I added the following properties like so:

configType.nano="-Xms512m -Xmx1024m -XX:+UseParallelGC  -XX:ParallelGCThreads=4 -XX:MaxGCPauseMillis=200 -XX:MaxGCMinorPauseMillis=75 -server -noverify  -Xshare:off -XX:+EliminateLocks -XX:GCTimeRatio=7"
configType.medium="-Xms1024m -Xmx2048m -XX:+UseParallelGC  -XX:ParallelGCThreads=8 -XX:MaxGCPauseMillis=200 -XX:MaxGCMinorPauseMillis=75 -server -noverify  -Xshare:off -XX:+EliminateLocks -XX:GCTimeRatio=7"
configType.large="-Xms4048m -Xmx4096m -XX:+UseParallelGC  -XX:ParallelGCThreads=16 -XX:MaxGCPauseMillis=200 -XX:MaxGCMinorPauseMillis=75 -server -noverify  -Xshare:off -XX:+EliminateLocks -XX:GCTimeRatio=7"

Then in the ‘build.gradle’, you can read in the JVMargs as a CLI property:

ext.javaMainClass = "demo.application.Application"

// -Pargs=configType=${configType}
application {
	mainClass = javaMainClass
	applicationDefaultJvmArgs = ['configType.'+configTypeDefault)]
	if (project.hasProperty("args")) {
		List temp = project.args.split(',')
			List l = args.split('=')
			if(l[0]=='configType' &&'configType.'+l[1])) {
				applicationDefaultJvmArgs = ['configType.'+l[1])]

NOTE: Make sure to change your ‘javaMainClass’

This allows you to pass your set your JVMArgs in your gradle properties per instance (with a default type) and pass it as a CLI arg when building your artifact.

gradle clean build --stacktrace  -Pargs=configType=nano