From e15778e343d744d9864d4e9637e0fc601688f58c Mon Sep 17 00:00:00 2001 From: Joshua Gleitze Date: Wed, 8 Jan 2025 13:45:11 +0100 Subject: [PATCH 1/6] test: test case reproducing the npm configuration cache issue #2372 --- .../spotless/NpmTestsWithoutNpmInstallationTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 22fe466dbe..8d78df006d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -177,4 +177,13 @@ void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception { throw e; } } + + @Test + public void supportsConfigurationCache() throws Exception { + setFile("build.gradle").toResource("com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "--configuration-cache", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); + } } From 078945d6e8298a84a17c55d178d801b12ac376aa Mon Sep 17 00:00:00 2001 From: Joshua Gleitze Date: Wed, 8 Jan 2025 13:47:12 +0100 Subject: [PATCH 2/6] fix: repair the configuration cache for NPM tasks by using a mutable instead of an immutable list workaround for #2372 --- .../main/java/com/diffplug/spotless/npm/NpmPathResolver.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java index 317c2a479b..afb0215114 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -35,7 +36,9 @@ public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable, this.explicitNpmExecutable = explicitNpmExecutable; this.explicitNodeExecutable = explicitNodeExecutable; this.explicitNpmrcFile = explicitNpmrcFile; - this.additionalNpmrcLocations = List.copyOf(additionalNpmrcLocations); + // We must not use an immutable list (e.g. List.copyOf) here, because immutable lists cannot be restored + // from Gradle’s serialisation. See https://github.com/diffplug/spotless/issues/2372 + this.additionalNpmrcLocations = new ArrayList<>(additionalNpmrcLocations); } /** From 6571ab11164266fe4d74501f7c0c279ff679d027 Mon Sep 17 00:00:00 2001 From: Joshua Gleitze Date: Wed, 8 Jan 2025 14:21:11 +0100 Subject: [PATCH 3/6] docs: document fix of #2372 --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6b9b44181f..077f18125d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed + * Node.JS-based tasks now work with the configuration cache ([#2372](https://github.com/diffplug/spotless/issues/2372)) ## [7.0.1] - 2025-01-07 ### Fixed From 87ac6a1a596c1c819c4da9fcd2274ce741fc630e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 8 Jan 2025 10:38:18 -0800 Subject: [PATCH 4/6] Update lib changelog. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 1a32103bf0..c714552607 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Node.JS-based tasks now work with the configuration cache ([#2372](https://github.com/diffplug/spotless/issues/2372)) ## [3.0.1] - 2025-01-07 ### Fixed From 6e2b09334a711c53a66ea08728d4b8fa74685056 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 8 Jan 2025 10:43:38 -0800 Subject: [PATCH 5/6] spotlessApply --- .../main/java/com/diffplug/spotless/npm/NpmPathResolver.java | 2 +- .../gradle/spotless/NpmTestsWithoutNpmInstallationTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java index afb0215114..f62340f074 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2024 DiffPlug + * Copyright 2020-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 8d78df006d..1d782120de 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From feaac904e8e01015c8aa267a9a049e94f9650470 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 8 Jan 2025 13:26:06 -0800 Subject: [PATCH 6/6] Make sure we use a recent version of `gradleRunner` --- .../gradle/spotless/NpmTestsWithoutNpmInstallationTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 1d782120de..6abbc108fa 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -182,7 +182,9 @@ void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception { public void supportsConfigurationCache() throws Exception { setFile("build.gradle").toResource("com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "--configuration-cache", "spotlessApply").build(); + BuildResult spotlessApply = gradleRunner() + .withGradleVersion(GradleVersionSupport.STABLE_CONFIGURATION_CACHE.version) + .withArguments("--stacktrace", "--configuration-cache", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean"); }