Skip to content

Commit

Permalink
Increase javac heap to 2g by default (up from 512m) (#2482)
Browse files Browse the repository at this point in the history
Increase javac heap to 2g by default (up from 512m). Existing overrides are not impacted.
  • Loading branch information
carterkozak authored Feb 1, 2023
1 parent 09a68d3 commit 55a9649
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-2482.v2.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Project> {

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);
}
}));
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 55a9649

Please sign in to comment.