@@ -92,16 +92,16 @@ tasks.withType(JavaCompile).configureEach {
9292
9393def createCompilerDirectives = tasks. register(' createCompilerDirectives' ) {
9494 def compilerDirectivesFile = project. layout. buildDirectory. file(' dh-compiler-directives.txt' )
95+ def compilerDirectivesText = new JsonBuilder ([{
96+ match ([' *.*' ] as List )
97+ // Note: there seems to be a bug where this option doesn't actually get picked up
98+ // So using '-XX:DisableIntrinsic=_currentThread' explicitly
99+ // DisableIntrinsic('_currentThread')
100+ }]). toPrettyString()
101+ it. inputs. property(' compilerDirectivesText' , compilerDirectivesText)
95102 it. outputs. file(compilerDirectivesFile)
96-
97103 doFirst {
98- def builder = new JsonBuilder ([{
99- match ([' *.*' ] as List )
100- // Note: there seems to be a bug where this option doesn't actually get picked up
101- // So using '-XX:DisableIntrinsic=_currentThread' explicitly
102- // DisableIntrinsic('_currentThread')
103- }])
104- compilerDirectivesFile. get(). asFile. text = builder. toPrettyString()
104+ compilerDirectivesFile. get(). asFile. text = compilerDirectivesText
105105 }
106106}
107107
@@ -123,30 +123,62 @@ def devJvmArgs = [
123123// '-XX:+PrintCompilation', // this optional line shows jit operations as they happen
124124]
125125
126+ // These are supposed to be generally applicable and recommended JVM options, but they aren't hard requirements.
127+ // Overly specific options do *not* belong here. For example, we should _not_ be setting something like `-Xmx4g` here.
128+ // If you are tempted to try and put system properties here (`-Dkey=value`), think again; there should be a more
129+ // appropriate place to set those.
130+ //
131+ // From the perspective of our application distribution, these options will be used as defaults for JAVA_OPTS
132+ // (if the user already has JAVA_OPTS set, these VM options will _not_ apply).
133+ def defaultJvmOptions = [
134+ ' -XX:+UseG1GC' ,
135+ ' -XX:MaxGCPauseMillis=100' ,
136+ ' -XX:+UseStringDeduplication' ,
137+ ]
138+
139+ def createVmOptions = tasks. register(' createVmOptions' ) {
140+ def vmOptionsFile = project. layout. buildDirectory. file(' dh-default.vmoptions' )
141+ def vmOptionsText = defaultJvmOptions. join(' \n ' )
142+ it. inputs. property(' vmOptionsText' , vmOptionsText)
143+ it. outputs. file(vmOptionsFile)
144+ doFirst {
145+ vmOptionsFile. get(). asFile. text = vmOptionsText
146+ }
147+ }
148+
126149tasks. withType(JavaExec ). configureEach {
127150 def compilerDirectivesFile = createCompilerDirectives. get(). outputs. files
151+ def vmOptionsFile = createVmOptions. get(). outputs. files
128152 inputs. files compilerDirectivesFile
153+ inputs. files vmOptionsFile
129154 javaLauncher. set runtimeLauncher
130- jvmArgs + = compilerArgs(compilerDirectivesFile. singleFile. path) + devJvmArgs
155+ // Note: we _could_ have the vmOptionsFile constituents directly listed instead of using -XX:VMOptionsFile.
156+ // That said, the current approach used here more closely matches how the application start script is defined.
157+ jvmArgs + = compilerArgs(compilerDirectivesFile. singleFile. path) + [" -XX:VMOptionsFile=${ vmOptionsFile.singleFile.path} " ] + devJvmArgs
131158}
132159
133160tasks. withType(Test ). configureEach {
134161 def compilerDirectivesFile = createCompilerDirectives. get(). outputs. files
162+ def vmOptionsFile = createVmOptions. get(). outputs. files
135163 inputs. files compilerDirectivesFile
136-
164+ inputs . files vmOptionsFile
137165 javaLauncher. set testRuntimeLauncher
138- jvmArgs + = compilerArgs(compilerDirectivesFile. singleFile. path) + devJvmArgs
166+ // Note: we _could_ have the vmOptionsFile constituents directly listed instead of using -XX:VMOptionsFile.
167+ // That said, the current approach used here more closely matches how the application start script is defined.
168+ jvmArgs + = compilerArgs(compilerDirectivesFile. singleFile. path) + [" -XX:VMOptionsFile=${ vmOptionsFile.singleFile.path} " ] + devJvmArgs
139169}
140170
141171tasks. withType(GroovyCompile ). configureEach {
142172 javaLauncher. set groovyCompilerLauncher
143173}
144174
145175plugins. withType(ApplicationPlugin ) {
146- applicationDistribution. into(' lib ' ) {
176+ applicationDistribution. into(' etc ' ) {
147177 from(createCompilerDirectives. get(). outputs. files)
178+ from(createVmOptions. get(). outputs. files)
148179 }
149180}
181+
150182tasks. withType(CreateStartScripts ). configureEach {
151183 def unixStartScript = resources. text. fromUri(getClass(). classLoader. getResource(' unixStartScript.txt' ))
152184 inputs. files unixStartScript
0 commit comments