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
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

## [Unreleased]
### Fixed
- `spotlessInternalRegisterDependencies` now writes its output under a build directory that is configured after the plugin is applied, instead of always under the default `build/`. ([#2114](https://github.com/diffplug/spotless/issues/2114))

## [8.10.0] - 2026-08-17
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.inject.Inject;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;
Expand Down Expand Up @@ -66,7 +67,8 @@ void setup() {
taskService = SpotlessTaskService.registerIfAbsent(getProject(), compositeBuildSuffix);
usesService(taskService);
getBuildEventsListenerRegistry().onTaskCompletion(taskService);
unitOutput = new File(getProject().getLayout().getBuildDirectory().getAsFile().get(), "tmp/spotless-register-dependencies");
// lazy, so a build directory set later in the buildscript still counts
getUnitOutput().set(getProject().getLayout().getBuildDirectory().file("tmp/spotless-register-dependencies"));
}

List<FormatterStep> steps = new ArrayList<>();
Expand All @@ -76,15 +78,12 @@ public List<FormatterStep> getSteps() {
return steps;
}

File unitOutput;

@OutputFile
public File getUnitOutput() {
return unitOutput;
}
public abstract RegularFileProperty getUnitOutput();

@TaskAction
public void trivialFunction() throws IOException {
File unitOutput = getUnitOutput().get().getAsFile();
Files.createParentDirs(unitOutput);
Files.write(Integer.toString(1), unitOutput, StandardCharsets.UTF_8);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2026 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 java.io.IOException;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

class RegisterDependenciesTaskBuildDirTest extends GradleIntegrationHarness {
@Test
void unitOutputFollowsCustomBuildDirectory() throws IOException {
setFile("settings.gradle").toLines(
"rootProject.name = 'buildDirTest'",
"include 'sub'");
setFile("build.gradle").toLines(
"plugins {",
" id 'com.diffplug.spotless'",
"}",
"repositories { mavenCentral() }",
"spotless { predeclareDeps() }",
"",
"spotlessPredeclare {",
" java { googleJavaFormat('1.17.0') }",
"}",
"",
"layout.buildDirectory = layout.projectDirectory.dir('custom-build')");
setFile("sub/build.gradle").toLines(
"plugins {",
" id 'com.diffplug.spotless'",
"}",
"spotless {",
" java {",
" target 'src/main/java/**/*.java'",
" googleJavaFormat('1.17.0')",
" }",
"}");
setFile("sub/src/main/java/Hello.java").toLines(
"public class Hello {}");

gradleRunner().withArguments("spotlessApply").build();

Assertions.assertThat(newFile("custom-build/tmp/spotless-register-dependencies"))
.as("register-dependencies output should follow the configured build directory")
.exists();
Assertions.assertThat(newFile("build/tmp/spotless-register-dependencies"))
.as("nothing should be written under the default build directory")
.doesNotExist();
}
}
Loading