Skip to content

Clean up junk from gradle's user home (~/.gradle/.tmp). #14385 #14387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
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
20 changes: 20 additions & 0 deletions gradle/hacks/wipe-temp.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.nio.file.Files
import java.time.temporal.ChronoUnit
import java.time.Instant


// See LUCENE-9471. We redirect temporary location for gradle
// so that it doesn't pollute user's tmp. Wipe it during a clean though.

configure(rootProject) {
gradle.buildFinished {
// we clean up the java.io.tmpdir we've redirected gradle to use (LUCENE-9471).
// these are still used and populated with junk.
rootProject.delete fileTree(".gradle/tmp").matching {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a comment above that this is in project's directory. This caused confusion in the original discussion!

include "gradle-worker-classpath*"
}

// clean up any files older than 3 hours from the user's gradle temp. the time
// limit is added so that we don't interfere with any concurrent builds... just in case.
def gradleTmp = rootProject.gradle.gradleUserHomeDir.toPath().resolve(".tmp")
if (Files.exists(gradleTmp)) {
Instant deadline = Instant.now().minus(3, ChronoUnit.HOURS);
try (var stream = Files.list(gradleTmp)) {
stream.forEach(path -> {
if (Files.getLastModifiedTime(path).toInstant().isBefore(deadline)) {
Files.deleteIfExists(path);
}
});
}
}
}
}

Expand Down