From eaf0e71aad5c4ee1a4366261b9f3232c7ee609fd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 2 Jan 2025 17:46:49 -0800 Subject: [PATCH] Using `custom` in a gradle script now works with and without the configuration cache. --- .../diffplug/gradle/spotless/FormatExtension.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 59898cbf56..69150724c1 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.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. @@ -457,12 +457,11 @@ protected Integer calculateState() throws Exception { */ public void custom(String name, Closure formatter) { requireNonNull(formatter, "formatter"); - Closure dehydrated = formatter.dehydrate(); - custom(name, new ClosureFormatterFunc(dehydrated)); + custom(name, new ClosureFormatterFunc(formatter)); } static class ClosureFormatterFunc implements FormatterFunc, Serializable { - private final Closure closure; + private Closure closure; ClosureFormatterFunc(Closure closure) { this.closure = closure; @@ -472,6 +471,14 @@ static class ClosureFormatterFunc implements FormatterFunc, Serializable { public String apply(String unixNewlines) { return closure.call(unixNewlines); } + + private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException { + stream.writeObject(closure.dehydrate()); + } + + private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException { + this.closure = (Closure) stream.readObject(); + } } /**