Skip to content
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* **BREAKING** Bump minimum supported Gradle version from 7.3 to 8.1. [#2719](https://github.com/diffplug/spotless/pull/2719)
### Fixed
* palantirJavaFormat is no longer arbitrarily set to outdated versions on Java 17, latest available version is always used ([#2686](https://github.com/diffplug/spotless/pull/2686) fixes [#2685](https://github.com/diffplug/spotless/issues/2685))
* Use Provider API for Gradle properties. ([#2718](https://github.com/diffplug/spotless/pull/2718)
### Removed
* **BREAKING** Drop support for older Ktlint versions. ([#2711](https://github.com/diffplug/spotless/pull/2711))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,7 @@ public LicenseHeaderConfig updateYearWithLatest(boolean updateYearWithLatest) {

FormatterStep createStep() {
return builder.withYearModeLazy(() -> {
if ("true".equals(spotless.project
.findProperty(LicenseHeaderStep.FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY()))) {
if (Boolean.parseBoolean(GradleCompat.findOptionalProperty(spotless.project, LicenseHeaderStep.FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY()))) {
return YearMode.SET_FROM_GIT;
} else {
boolean updateYear = updateYearWithLatest == null ? getRatchetFrom() != null : updateYearWithLatest;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2025 DiffPlug
*
* 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.diffplug.gradle.spotless;

import javax.annotation.Nullable;

import org.gradle.api.Project;

public final class GradleCompat {
private GradleCompat() {}

@Nullable public static String findOptionalProperty(Project project, String propertyName) {
@Nullable String value = project.getProviders().gradleProperty(propertyName).getOrNull();
if (value != null) {
return value;
}
@Nullable Object property = project.findProperty(propertyName);
if (property != null) {
return property.toString();
}
return null;
}

public static boolean isPropertyPresent(Project project, String propertyName) {
return project.getProviders().gradleProperty(propertyName).isPresent() ||
project.hasProperty(propertyName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ static class State extends NoLambda.EqualityBasedOnSerialization {
final boolean useStdOut;

State(Project project) {
path = (String) project.findProperty(PROPERTY);
path = GradleCompat.findOptionalProperty(project, PROPERTY);
if (path != null) {
useStdIn = project.hasProperty(USE_STD_IN);
useStdOut = project.hasProperty(USE_STD_OUT);
useStdIn = GradleCompat.isPropertyPresent(project, USE_STD_IN);
useStdOut = GradleCompat.isPropertyPresent(project, USE_STD_OUT);
} else {
useStdIn = false;
useStdOut = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void apply(Project project) {
+ "https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation");
}
// if -PspotlessModern=true, then use the modern stuff instead of the legacy stuff
if (project.hasProperty(SPOTLESS_MODERN)) {
if (GradleCompat.isPropertyPresent(project, SPOTLESS_MODERN)) {
project.getLogger().warn("'spotlessModern' has no effect as of Spotless 5.0, recommend removing it.");
}
// make sure there's a `clean` and a `check`
Expand Down
Loading