Skip to content
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

SOLR-16641 - Generate gradle.properties from gradlew #1320

Merged
merged 11 commits into from Feb 6, 2023
2 changes: 0 additions & 2 deletions .github/workflows/bin-solr-test.yml
Expand Up @@ -34,8 +34,6 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-binsolr-
${{ runner.os }}-gradle-
- name: Initialize gradle settings
run: ./gradlew localSettings
- name: Test the bin/solr script
run: ./gradlew integrationTests
- name: Archive logs
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/docker-test.yml
Expand Up @@ -42,8 +42,6 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-docker-
${{ runner.os }}-gradle-
- name: Initialize gradle settings
run: ./gradlew localSettings
- name: Build Docker image with Gradle
run: ./gradlew solr:docker:docker
- name: Run tests on Docker image
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/gradle-precommit.yml
Expand Up @@ -34,9 +34,6 @@ jobs:
${{ runner.os }}-gradle-precommit-
${{ runner.os }}-gradle-
- name: Initialize gradle settings
run: ./gradlew localSettings

- name: Run gradle check (without tests)
run: ./gradlew check -x test -Ptask.times=true

Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/solrj-test.yml
Expand Up @@ -33,7 +33,5 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-solrj-
${{ runner.os }}-gradle-
- name: Initialize gradle settings
run: ./gradlew localSettings
- name: Test the SolrJ Package
run: ./gradlew solr:solrj:test
1 change: 1 addition & 0 deletions dev-docs/how-to-contribute.adoc
Expand Up @@ -17,6 +17,7 @@ In order to make a new contribution to Solr you will use the fork you have creat
1. Create a new Jira issue in the Solr project: https://issues.apache.org/jira/projects/SOLR/issues
2. Create a new branch in your Solr fork to provide a PR for your contribution on the newly created issue. Make any necessary changes for the given bug/feature in that branch. You can use additional information in these dev-docs to build and test your code as well as ensure it passes code quality checks.
3. Once you are satisfied with your changes, get your branch ready for a PR by running `./gradlew tidy updateLicenses check -x test`. This will format your source code, update licenses of any dependency version changes and run all pre-commit tests. Commit the changes.
* Note: the `check` command requires `perl` and `python3` to be present on your `PATH` to validate documentation.
4. Open a PR of your branch against the `main` branch of the apache/solr repository. When you open a PR on your fork, this should be the default option.
* The title of your PR should include the Solr Jira issue that you opened, i.e. `SOLR-12345: New feature`.
* The PR description will automatically populate with a pre-set template that you will need to fill out.
Expand Down
2 changes: 2 additions & 0 deletions dev-docs/solr-source-code.adoc
Expand Up @@ -38,6 +38,8 @@ If you want to build the documentation, type `./gradlew -p solr documentation`.

`./gradlew check` will assemble Solr and run all validation tasks unit tests.

NOTE: the `check` command requires `perl` and `python3` to be present on your `PATH` to validate documentation.

To build the final Solr artifacts run `./gradlew assemble`.

Lastly, there is developer oriented documentation in `./dev-docs/README.adoc` that
Expand Down
2 changes: 0 additions & 2 deletions dev-tools/scripts/releaseWizard.yaml
Expand Up @@ -356,8 +356,6 @@ groups:
- !Command
cmd: git pull --ff-only
stdout: true
- !Command
cmd: "{{ gradle_cmd }} localSettings"
- !Command
cmd: "{{ gradle_cmd }} clean check -x test"
- !Todo
Expand Down
79 changes: 0 additions & 79 deletions gradle/generation/local-settings.gradle
Expand Up @@ -45,83 +45,4 @@ configure(rootProject) {
}
}
}

colvinco marked this conversation as resolved.
Show resolved Hide resolved
task localSettings() {
doFirst {
// If we don't have the defaults yet, create them.
if (hasDefaults) {
logger.lifecycle("Local settings already exist, skipping generation.")
} else {
// Approximate a common-sense default for running gradle/tests with parallel
// workers: half the count of available cpus but not more than 12.
def cpus = Runtime.runtime.availableProcessors()
def maxWorkers = (int) Math.max(1d, Math.min(cpus * 0.5d, 12))
def testsJvms = (int) Math.max(1d, Math.min(cpus * 0.5d, 12))

// Write the defaults for this machine.
rootProject.file("gradle.properties").write("""
# These settings have been generated automatically on the first run.
# See gradlew :helpLocalSettings for more information.
systemProp.file.encoding=UTF-8

# Set up gradle JVM defaults.
#
# We also open up internal compiler modules for spotless/ google java format.
org.gradle.jvmargs=-Xmx1g -XX:TieredStopAtLevel=1 -XX:+UseParallelGC -XX:ActiveProcessorCount=1 \\
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

# Run at normal priority, in parallel
org.gradle.parallel=true
org.gradle.priority=normal

# This setting enables local task output caches. This will speed up
# your local builds in most cases but will also consume disk space in your
# gradle home. See SOLR-15603 for details.
# org.gradle.caching=true

# Silence gradle warnings. We'll deal with them when we upgrade the wrapper.
org.gradle.warning.mode=none

# You may disable the background daemon if it consumes too much memory.
org.gradle.daemon=true
# timeout after 15 mins of inactivity.
org.gradle.daemon.idletimeout=900000

# Maximum number of parallel gradle workers.
org.gradle.workers.max=${maxWorkers}

# Maximum number of test JVMs forked per test task.
tests.jvms=${testsJvms}

# Disable auto JVM provisioning (we don't use toolchains yet but want no surprises).
org.gradle.java.installations.auto-download=false

# Set these to enable automatic JVM location discovery.
org.gradle.java.installations.fromEnv=JDK11,JDK12,JDK13,JDK14,JDK15,JDK16,JDK17
org.gradle.java.installations.paths=(custom paths)

""", "UTF-8")

logger.log(LogLevel.WARN, "\nIMPORTANT. This is the first time you ran the build. " +
"I wrote some sane defaults (for this machine) to 'gradle.properties', " +
"they will be picked up on consecutive gradle invocations (not this one).\n\n" +
"Run gradlew :helpLocalSettings for more information.")
}
}
}
}

if (!hasDefaults) {
// Make all tasks depend on local setup to make sure it'll run.
allprojects {
tasks.all { task ->
if (task != rootProject.localSettings) {
task.dependsOn rootProject.localSettings
}
}
}
}
43 changes: 43 additions & 0 deletions gradle/template.gradle.properties
@@ -0,0 +1,43 @@
# See gradlew :helpLocalSettings for more information on configuring this file.
colvinco marked this conversation as resolved.
Show resolved Hide resolved
systemProp.file.encoding=UTF-8

# Set up gradle JVM defaults.
#
# We also open up internal compiler modules for spotless/ google java format.
org.gradle.jvmargs=-Xmx1g -XX:TieredStopAtLevel=1 -XX:+UseParallelGC -XX:ActiveProcessorCount=1 \
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

# Run at normal priority, in parallel
org.gradle.parallel=true
org.gradle.priority=normal

# This setting enables local task output caches. This will speed up
# your local builds in most cases but will also consume disk space in your
# gradle home. See SOLR-15603 for details.
# org.gradle.caching=true

# Silence gradle warnings. We'll deal with them when we upgrade the wrapper.
org.gradle.warning.mode=none

# You may disable the background daemon if it consumes too much memory.
org.gradle.daemon=true
# timeout after 15 mins of inactivity.
org.gradle.daemon.idletimeout=900000

# Maximum number of parallel gradle workers.
org.gradle.workers.max=2

# Maximum number of test JVMs forked per test task.
tests.jvms=2

# Disable auto JVM provisioning (we don't use toolchains yet but want no surprises).
org.gradle.java.installations.auto-download=false

# Set these to enable automatic JVM location discovery.
org.gradle.java.installations.fromEnv=JDK11,JDK12,JDK13,JDK14,JDK15,JDK16,JDK17
janhoy marked this conversation as resolved.
Show resolved Hide resolved
org.gradle.java.installations.paths=(custom paths)
colvinco marked this conversation as resolved.
Show resolved Hide resolved
colvinco marked this conversation as resolved.
Show resolved Hide resolved

4 changes: 2 additions & 2 deletions gradle/validation/gradlew-scripts-tweaked.gradle
Expand Up @@ -32,8 +32,8 @@ configure(rootProject) {
doFirst {
scripts.each { file ->
def content = new String(file.readBytes(), StandardCharsets.US_ASCII)
if (content.indexOf("Don't fork a daemon mode on initial run that generates local defaults") < 0) {
throw new GradleException("Launch script ${file} does not have a manual daemon tweak (see LUCENE-9232).")
if (content.indexOf("GradlePropertiesGenerator") < 0) {
throw new GradleException("Launch script ${file} does not have a tweak to generate gradle.properties (see SOLR-16641).")
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions gradlew
Expand Up @@ -163,11 +163,16 @@ fi

CLASSPATH=$GRADLE_WRAPPER_JAR

# Don't fork a daemon mode on initial run that generates local defaults.
GRADLE_DAEMON_CTRL=
# START OF SOLR CUSTOMIZATION
# Generate gradle.properties if they don't exist
if [ ! -e "$APP_HOME/gradle.properties" ]; then
GRADLE_DAEMON_CTRL=--no-daemon
"$JAVACMD" $JAVA_OPTS --source 11 "$APP_HOME/buildSrc/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java" "$APP_HOME/gradle/template.gradle.properties" "$APP_HOME/gradle.properties"
risdenk marked this conversation as resolved.
Show resolved Hide resolved
GENERATOR_STATUS=$?
if [ "$WRAPPER_STATUS" -ne 0 ]; then
exit $WRAPPER_STATUS
fi
colvinco marked this conversation as resolved.
Show resolved Hide resolved
fi
# END OF SOLR CUSTOMIZATION

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
Expand Down Expand Up @@ -237,7 +242,6 @@ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
$GRADLE_DAEMON_CTRL \
"$@"

# Stop when "xargs" is not available.
Expand Down
15 changes: 11 additions & 4 deletions gradlew.bat
Expand Up @@ -80,12 +80,19 @@ IF %ERRORLEVEL% NEQ 0 goto fail
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Don't fork a daemon mode on initial run that generates local defaults.
SET GRADLE_DAEMON_CTRL=
IF NOT EXIST "%DIRNAME%\gradle.properties" SET GRADLE_DAEMON_CTRL=--no-daemon
@rem START OF SOLR CUSTOMIZATION
@rem Generate gradle.properties if they don't exist
IF NOT EXIST "%APP_HOME%\gradle.properties" (
@rem local expansion is needed to check ERRORLEVEL inside control blocks.
setlocal enableDelayedExpansion
"%JAVA_EXE%" --source 11 "%APP_HOME%/buildSrc/src/main/java/org/apache/lucene/gradle/GradlePropertiesGenerator.java" "%APP_HOME%\gradle\template.gradle.properties" "%APP_HOME%\gradle.properties"
IF %ERRORLEVEL% NEQ 0 goto fail
endlocal
)
@rem END OF SOLR CUSTOMIZATION

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %GRADLE_DAEMON_CTRL% %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down