Skip to content

Commit cee4960

Browse files
authored
Merge pull request #588 from diffplug/feat/outside-project-dir
Better error message if you try to format a file outside the project directory.
2 parents 8a8a1c2 + 2521e89 commit cee4960

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

plugin-gradle/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
99
* Users can now run `spotlessCheck` and `spotlessApply` in the same build. ([#584](https://github.com/diffplug/spotless/pull/584))
1010
* Fixed intermittent `UnsatisfiedLinkError` in nodejs-based steps. ([#586](https://github.com/diffplug/spotless/pull/586))
1111
* Also, a shared library used by the nodejs steps used to be extracted into the user home directory, but now it is extracted into `{rootProject}/build/spotless-nodejs-cache`.
12+
* Starting in `4.0`, it is no longer possible for a project to format files which are not within its project folder (for example, `:a` can no longer format files in `:b`). We did not explicitly note this in the changelog entry for `4.0`, and we gave a very confusing error message if users tried. We now give a more helpful error message, and this breaking change has been retroactively noted in the changelog for `4.0.0`. ([#588](https://github.com/diffplug/spotless/pull/588))
1213

1314
## [4.0.1] - 2020-05-21
1415
### Fixed
@@ -21,6 +22,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2122
* Support for the gradle build cache. ([#576](https://github.com/diffplug/spotless/pull/576))
2223
* The local cache will work great, but the remote cache will always miss until [#566](https://github.com/diffplug/spotless/issues/566) is resolved.
2324
### Removed
25+
* **BREAKING** it used to be possible for any project to format files in any other project. For example, `:a` could format files in `:b`. It is now only possible to format files within the project directory. It is okay (but not advised) to format files in subprojects, since they are within the project directory.
2426
* (Power users only) **BREAKING** `void SpotlessTask::setCheck()` and `setApply()` have been removed. ([#576](https://github.com/diffplug/spotless/pull/576))
2527
* Previously, the `check` and `apply` tasks were just marker tasks, and they called `setCheck` and `setApply` on the "worker" task. Now `check` and `apply` are real tasks in their own right, so the marker-task kludge is no longer necessary.
2628
### Changed

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.gradle.api.tasks.incremental.IncrementalTaskInputs;
4545

4646
import com.diffplug.common.base.Errors;
47+
import com.diffplug.common.base.StringPrinter;
4748
import com.diffplug.spotless.FormatExceptionPolicy;
4849
import com.diffplug.spotless.FormatExceptionPolicyStrict;
4950
import com.diffplug.spotless.Formatter;
@@ -245,7 +246,11 @@ private void deletePreviousResult(File input) throws IOException {
245246
private File getOutputFile(File input) {
246247
String outputFileName = FormatExtension.relativize(getProject().getProjectDir(), input);
247248
if (outputFileName == null) {
248-
outputFileName = input.getAbsolutePath();
249+
throw new IllegalArgumentException(StringPrinter.buildString(printer -> {
250+
printer.println("Spotless error! All target files must be within the project root. In project " + getProject().getPath());
251+
printer.println(" root dir: " + getProject().getProjectDir().getAbsolutePath());
252+
printer.println(" target: " + input.getAbsolutePath());
253+
}));
249254
}
250255
return new File(outputDirectory, outputFileName);
251256
}

0 commit comments

Comments
 (0)