From 9d9a041a72aafa819f04cdd980873a346467bddb Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Wed, 1 Feb 2023 11:23:27 -0500 Subject: [PATCH 1/2] Increase javac heap to 2g by default (up from 512m) --- .../palantir/baseline/plugins/Baseline.java | 1 + .../plugins/BaselineJavaCompilerHeap.java | 41 ++++++++++++ .../BaselineJavaCompilerHeapTest.groovy | 62 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineJavaCompilerHeap.java create mode 100644 gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineJavaCompilerHeapTest.groovy diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/Baseline.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/Baseline.java index 467f8ffd3..b06bab275 100644 --- a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/Baseline.java +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/Baseline.java @@ -58,6 +58,7 @@ public void apply(Project project) { proj.getPluginManager().apply(BaselineTesting.class); proj.getPluginManager().apply(BaselineTestHeap.class); proj.getPluginManager().apply(BaselineJavaCompilerDiagnostics.class); + proj.getPluginManager().apply(BaselineJavaCompilerHeap.class); proj.getPluginManager().apply(BaselineJavaParameters.class); proj.getPluginManager().apply(BaselineImmutables.class); proj.getPluginManager().apply(BaselineModuleJvmArgs.class); diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineJavaCompilerHeap.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineJavaCompilerHeap.java new file mode 100644 index 000000000..6ab15f66c --- /dev/null +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineJavaCompilerHeap.java @@ -0,0 +1,41 @@ +/* + * (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.baseline.plugins; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.tasks.compile.ForkOptions; +import org.gradle.api.tasks.compile.JavaCompile; + +/** + * Increases the default {@link JavaCompile} task heap from {@code 512m} to {@code 2g}. + */ +public final class BaselineJavaCompilerHeap implements Plugin { + + private static final String JAVAC_HEAP = "2g"; + + @Override + public void apply(Project proj) { + proj.afterEvaluate( + project -> project.getTasks().withType(JavaCompile.class).configureEach(javaCompileTask -> { + ForkOptions options = javaCompileTask.getOptions().getForkOptions(); + if (options.getMemoryMaximumSize() == null) { + options.setMemoryMaximumSize(JAVAC_HEAP); + } + })); + } +} diff --git a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineJavaCompilerHeapTest.groovy b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineJavaCompilerHeapTest.groovy new file mode 100644 index 000000000..49c25eafa --- /dev/null +++ b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineJavaCompilerHeapTest.groovy @@ -0,0 +1,62 @@ +/* + * (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.baseline + +import com.palantir.baseline.plugins.BaselineJavaCompilerHeap +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.testfixtures.ProjectBuilder +import spock.lang.Specification + +class BaselineJavaCompilerHeapTest extends Specification { + + def testDefault() { + when: + def project = ProjectBuilder.builder().build() + project.buildscript { + repositories { + mavenCentral() + } + } + project.plugins.apply 'java' + project.plugins.apply BaselineJavaCompilerHeap + project.evaluate() + + then: + JavaCompile compileTask = project.tasks.getByName('compileJava').asType(JavaCompile.class) + compileTask.options.forkOptions.memoryMaximumSize == "2g" + } + + def testOverridden() { + when: + def project = ProjectBuilder.builder().build() + project.buildscript { + repositories { + mavenCentral() + } + } + project.plugins.apply 'java' + project.tasks.compileJava { + options.forkOptions.memoryMaximumSize = "768m" + } + project.plugins.apply BaselineJavaCompilerHeap + project.evaluate() + + then: + JavaCompile compileTask = project.tasks.getByName('compileJava').asType(JavaCompile.class) + compileTask.options.forkOptions.memoryMaximumSize == "768m" + } +} From 5694e75f83ab3e6cf77ef175f5d8c672d0891b76 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Wed, 1 Feb 2023 16:26:02 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-2482.v2.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/@unreleased/pr-2482.v2.yml diff --git a/changelog/@unreleased/pr-2482.v2.yml b/changelog/@unreleased/pr-2482.v2.yml new file mode 100644 index 000000000..713a2cb29 --- /dev/null +++ b/changelog/@unreleased/pr-2482.v2.yml @@ -0,0 +1,6 @@ +type: improvement +improvement: + description: Increase javac heap to 2g by default (up from 512m). Existing overrides + are not impacted. + links: + - https://github.com/palantir/gradle-baseline/pull/2482