Skip to content

Commit

Permalink
Make sure Gradle cache is not confused by maps
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd authored and holly-cummins committed Jul 31, 2024
1 parent fc6c749 commit ea48da9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -60,6 +61,8 @@ Map<String, String> cachingRelevantProperties(List<String> propertyPatterns) {
Predicate<Map.Entry<String, ?>> keyPredicate = e -> patterns.stream().anyMatch(p -> p.matcher(e.getKey()).matches());
return values.entrySet().stream()
.filter(keyPredicate)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (s, s2) -> {
throw new IllegalArgumentException("Duplicate key");
}, TreeMap::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;

import javax.inject.Inject;
Expand Down Expand Up @@ -76,7 +78,8 @@ Map<String, String> getInternalTaskConfig() {
// an input to the cache key. We need to declare these properties as inputs, because those influence the
// execution.
// Documented here: https://docs.gradle.org/current/userguide/build_cache.html#sec:task_output_caching_inputs
return Map.of("launchMode", launchMode.name(), "inputSourceSetName", inputSourceSetName);
return Collections.unmodifiableMap(
new TreeMap<>(Map.of("launchMode", launchMode.name(), "inputSourceSetName", inputSourceSetName)));
}

@InputFiles
Expand Down

0 comments on commit ea48da9

Please sign in to comment.