From 3eecd3f1beafd2e333580b1bd7f6ab2f54cef915 Mon Sep 17 00:00:00 2001 From: Brian Laub Date: Mon, 30 Jan 2023 10:30:09 -0500 Subject: [PATCH 1/3] ensure tasks that use moduleJvmArgs have task inputs set correctly The BaselineModuleJvmArgs plugin configures several tasks from the 'java' plugin to use values from the 'moduleJvmArgs' extension (e.g. to update compiler arguments, output values to the jar manifest, etc.). However, when the value on the extension changes, those tasks are not re-run. To fix that, add input properties for each task that uses moduleJvmArgs so that when the extension value changes, the task will no longer be up-to-date. Fixes #2476 --- .../plugins/BaselineModuleJvmArgs.java | 19 ++++++++ ...aselineModuleJvmArgsIntegrationTest.groovy | 43 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineModuleJvmArgs.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineModuleJvmArgs.java index 5be2d3bff..5687c583d 100644 --- a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineModuleJvmArgs.java +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineModuleJvmArgs.java @@ -111,6 +111,8 @@ public Iterable asArguments() { return arguments; } }); + + setTaskInputsFromExtension(javaCompile, extension); }); TaskProvider javadocTaskProvider = null; @@ -175,6 +177,8 @@ public void execute(Task task) { } } }); + + setTaskInputsFromExtension(javadocTask, extension); }); } }); @@ -198,6 +202,8 @@ public Iterable asArguments() { return arguments; } }); + + setTaskInputsFromExtension(test, extension); } }); @@ -220,6 +226,8 @@ public Iterable asArguments() { return arguments; } }); + + setTaskInputsFromExtension(javaExec, extension); } }); @@ -256,11 +264,22 @@ public void execute(Manifest manifest) { }); } }); + + setTaskInputsFromExtension(jar, extension); } }); }); } + private static void setTaskInputsFromExtension(Task task, BaselineModuleJvmArgsExtension extension) { + task.getInputs() + .property("baseline-module-jvm-args-extension-exports", extension.exports()); + task.getInputs() + .property("baseline-module-jvm-args-extension-opens", extension.opens()); + task.getInputs() + .property("baseline-module-jvm-args-extension-enablePreview", extension.getEnablePreview()); + } + private static void addManifestAttribute( Jar jarTask, Manifest manifest, String attributeName, Provider> valueProperty) { Project project = jarTask.getProject(); diff --git a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineModuleJvmArgsIntegrationTest.groovy b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineModuleJvmArgsIntegrationTest.groovy index 1bdcce7a5..02131cf01 100644 --- a/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineModuleJvmArgsIntegrationTest.groovy +++ b/gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineModuleJvmArgsIntegrationTest.groovy @@ -426,4 +426,47 @@ class BaselineModuleJvmArgsIntegrationTest extends IntegrationSpec { ExecutionResult result = runTasksWithFailure('jar') result.standardError.contains('separated by a single slash') } + + def 'Task not up-to-date when extension value changes'() { + when: + buildFile << ''' + application { + mainClass = 'com.Example' + } + + moduleJvmArgs { + exports = ['java.management/sun.management'] + } + '''.stripIndent(true) + writeJavaSourceFile(''' + package com; + public class Example { + public static void main(String[] args) { + System.out.println(String.join( + " ", + java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments())); + } + } + '''.stripIndent(true)) + + ExecutionResult resultBeforeChange = runTasksSuccessfully('jar') + + buildFile.text = standardBuildFile + ''' + application { + mainClass = 'com.Example\' + } + + moduleJvmArgs { + exports = ['java.management/sun.management123'] + } + '''.stripIndent(true) + + ExecutionResult resultAfterChange = runTasksSuccessfully('jar') + + then: + !resultBeforeChange.wasUpToDate('jar') + resultBeforeChange.wasExecuted('jar') + !resultAfterChange.wasUpToDate('jar') + resultAfterChange.wasExecuted('jar') + } } From eaf48ae563333a791efcb4b7901b6b46346283e8 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Mon, 30 Jan 2023 15:34:34 +0000 Subject: [PATCH 2/3] Add generated changelog entries --- changelog/@unreleased/pr-2477.v2.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/@unreleased/pr-2477.v2.yml diff --git a/changelog/@unreleased/pr-2477.v2.yml b/changelog/@unreleased/pr-2477.v2.yml new file mode 100644 index 000000000..5cf8fd0f7 --- /dev/null +++ b/changelog/@unreleased/pr-2477.v2.yml @@ -0,0 +1,6 @@ +type: fix +fix: + description: add input properties for each task that uses moduleJvmArgs so that + when the extension value changes, the task will no longer be up-to-date. + links: + - https://github.com/palantir/gradle-baseline/pull/2477 From 53ee40431341464236e776bf1ba2047c3dccc68a Mon Sep 17 00:00:00 2001 From: Brian Laub Date: Mon, 30 Jan 2023 10:43:09 -0500 Subject: [PATCH 3/3] spotlessApply --- .../palantir/baseline/plugins/BaselineModuleJvmArgs.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineModuleJvmArgs.java b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineModuleJvmArgs.java index 5687c583d..c983cb9bb 100644 --- a/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineModuleJvmArgs.java +++ b/gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineModuleJvmArgs.java @@ -272,12 +272,9 @@ public void execute(Manifest manifest) { } private static void setTaskInputsFromExtension(Task task, BaselineModuleJvmArgsExtension extension) { - task.getInputs() - .property("baseline-module-jvm-args-extension-exports", extension.exports()); - task.getInputs() - .property("baseline-module-jvm-args-extension-opens", extension.opens()); - task.getInputs() - .property("baseline-module-jvm-args-extension-enablePreview", extension.getEnablePreview()); + task.getInputs().property("baseline-module-jvm-args-extension-exports", extension.exports()); + task.getInputs().property("baseline-module-jvm-args-extension-opens", extension.opens()); + task.getInputs().property("baseline-module-jvm-args-extension-enablePreview", extension.getEnablePreview()); } private static void addManifestAttribute(