Skip to content

Commit 5ade001

Browse files
authored
Fix forUseAtConfigurationTime warnings from the BlowdryerSetupPlugin. (#38)
2 parents c6c8056 + 487b69b commit 5ade001

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Remove `Provider.forUseAtConfigurationTime method has been deprecated` warnings in recent versions of Gradle. ([#38](https://github.com/diffplug/blowdryer/pull/38))
810

911
## [1.7.0] - 2023-01-28
1012
### Added

src/main/java/com/diffplug/blowdryer/BlowdryerSetupPlugin.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import org.gradle.api.GradleException;
2121
import org.gradle.api.Plugin;
2222
import org.gradle.api.initialization.Settings;
23+
import org.gradle.api.provider.Provider;
2324

2425
/** Gradle settings plugin which configures the source URL and version. */
2526
public class BlowdryerSetupPlugin implements Plugin<Settings> {
2627
static final String MINIMUM_GRADLE = "6.8";
28+
static final String STOP_FORUSE_AT_CONFIGURATION_TIME = "7.4";
2729

2830
private static final Pattern BAD_SEMVER = Pattern.compile("(\\d+)\\.(\\d+)");
2931

@@ -32,7 +34,11 @@ public void apply(Settings settings) {
3234
if (badSemver(settings.getGradle().getGradleVersion()) < badSemver(MINIMUM_GRADLE)) {
3335
throw new GradleException("Blowdryer requires Gradle " + MINIMUM_GRADLE + " or newer, this was " + settings.getGradle().getGradleVersion());
3436
}
35-
Blowdryer.initTempDir(settings.getProviders().systemProperty("java.io.tmpdir").forUseAtConfigurationTime().get());
37+
Provider<String> tmpDir = settings.getProviders().systemProperty("java.io.tmpdir");
38+
String tmpDirPath = badSemver(settings.getGradle().getGradleVersion()) >= badSemver(STOP_FORUSE_AT_CONFIGURATION_TIME) ? // depends on Gradle version
39+
tmpDir.get() : // Gradle 7.4 and later
40+
tmpDir.forUseAtConfigurationTime().get(); // before Gradle 7.4
41+
Blowdryer.initTempDir(tmpDirPath);
3642
settings.getExtensions().create(BlowdryerSetup.NAME, BlowdryerSetup.class, settings.getRootDir());
3743
}
3844

src/test/java/com/diffplug/blowdryer/BlowdryerPluginTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Locale;
2121
import java.util.stream.Collectors;
2222
import org.assertj.core.api.Assertions;
23+
import org.gradle.testkit.runner.BuildResult;
2324
import org.junit.Assume;
2425
import org.junit.Test;
2526

@@ -377,4 +378,11 @@ public void tooOldError() throws IOException {
377378
Assertions.assertThat(gradleRunner().withGradleVersion("6.7").buildAndFail().getOutput().replace("\r\n", "\n"))
378379
.contains("Blowdryer requires Gradle 6.8 or newer, this was 6.7");
379380
}
381+
382+
@Test
383+
public void deprecationError() throws IOException {
384+
settingsGithub("test/2/a");
385+
BuildResult build = gradleRunner().withGradleVersion("8.5").withArguments("--warning-mode=fail").build();
386+
Assertions.assertThat(build.getOutput()).doesNotContain("Provider.forUseAtConfigurationTime method has been deprecated");
387+
}
380388
}

0 commit comments

Comments
 (0)