diff --git a/build.gradle b/build.gradle index 9556695143d..5e2f79906d9 100644 --- a/build.gradle +++ b/build.gradle @@ -153,3 +153,4 @@ apply from: file('gradle/documentation/markdown.gradle') apply from: file('gradle/documentation/render-javadoc.gradle') apply from: file('gradle/hacks/findbugs.gradle') +apply from: file('gradle/hacks/gradle.gradle') diff --git a/gradle/hacks/gradle.gradle b/gradle/hacks/gradle.gradle new file mode 100644 index 00000000000..acb93947ac6 --- /dev/null +++ b/gradle/hacks/gradle.gradle @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +// 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) { + task cleanGradleTmp(type: Delete) { + delete fileTree(".gradle/tmp").matching { + include "gradle-worker-classpath*" + } + } + + clean.dependsOn cleanGradleTmp +} + +// Make sure we clean up after running tests. +allprojects { + plugins.withType(JavaPlugin) { + def temps = [] + + task cleanTaskTmp() { + doLast { + temps.each { temp -> + project.delete fileTree(temp).matching { + include "jar_extract*" + } + } + } + } + + tasks.withType(Test) { + finalizedBy rootProject.cleanGradleTmp, cleanTaskTmp + temps += temporaryDir + } + } +} diff --git a/gradlew b/gradlew index 32be99f1d9a..b275a1259b3 100755 --- a/gradlew +++ b/gradlew @@ -102,12 +102,21 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi +# LUCENE-9471: workaround for gradle leaving junk temp. files behind. +GRADLE_TEMPDIR=$APP_HOME/.gradle/tmp +mkdir -p $GRADLE_TEMPDIR +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + GRADLE_TEMPDIR=`cygpath --path --mixed "$GRADLE_TEMPDIR"` +fi +DEFAULT_JVM_OPTS="$DEFAULT_JVM_OPTS \"-Djava.io.tmpdir=$GRADLE_TEMPDIR\"" + # LUCENE-9266: verify and download the gradle wrapper jar if we don't have one. if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` fi GRADLE_WRAPPER_JAR=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if ! $JAVACMD --source 11 $APP_HOME/buildSrc/src/main/java/org/apache/lucene/gradle/WrapperDownloader.java $GRADLE_WRAPPER_JAR ; then + echo "\nSomething went wrong. Make sure you're using Java 11 or later." exit $? fi diff --git a/gradlew.bat b/gradlew.bat index 1f58301d4bc..6f950711b44 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -32,6 +32,11 @@ set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" +@rem LUCENE-9471: workaround for gradle leaving junk temp. files behind. +SET GRADLE_TEMPDIR=%DIRNAME%\.gradle\tmp +IF NOT EXIST "%GRADLE_TEMPDIR%" MKDIR %GRADLE_TEMPDIR% +SET DEFAULT_JVM_OPTS=%DEFAULT_JVM_OPTS% -Djava.io.tmpdir=%GRADLE_TEMPDIR% + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome