Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase javac heap to 2g by default (up from 512m) #2482

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, afterEvaluate is used because we want to check if something else already set options.getMemoryMaximumSize?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you even added a test for this! :)

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"
}
}