¿Cómo le digo a Gradle que use una versión específica de JDK?
No puedo hacer que esto funcione.
Escenario:
- Tengo una aplicación creada con gradle
- La aplicación utiliza JavaFX
Lo que quiero
- Utilice una variable (definida por máquina desarrolladora) que apunte a una instalación de un JDK que se utilizará para construir toda la aplicación / tests / ...
Pensé en tener el archivo gradle.properties
, definiendo la variable. Algo así como
JAVA_HOME_FOR_MY_PROJECT=<path to my desired JDK>
Lo que no want
- punto
JAVA_HOME
al JDK deseado
Podría vivir con muchas sugerencias:
- una solución que define una variable de entorno del sistema que puedo comprobar en mi compilación.gradle script
- una variable definida en gradle.propiedades
- sobreescribir la variable JAVA_HOME solo para el contexto de compilación (algo así como
use JAVA_HOME=<my special JDK path defined somewhere else defined>
) - algo más en lo que no pensé{[11]]}
Pregunta:
- Cómo cablear una variable (como siempre definido, como variable en el
gradle.properties
, variable de entorno del sistema, ...) al proceso de construcción?
Tengo más de un JDK7 disponible y necesito apuntar a una versión especial (versión mínima JDK_u).
Cualquier respuesta es apreciada y estoy agradecido por cada indicio en la dirección correcta.
9 answers
De dos maneras
En {[1] } en el directorio
.gradle
en su conjuntoHOME_DIRECTORY
org.gradle.java.home=/path_to_jdk_directory
-
En su
build.gradle
compileJava.options.fork = true compileJava.options.forkOptions.executable = /path_to_javac
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-13 05:13:32
Si agregas JDK_PATH en gradle.properties su compilación se vuelve dependiente de esa ruta en particular. En su lugar, ejecute gradle task con el siguiente parametemer de línea de comandos
gradle build -Dorg.gradle.java.home=/JDK_PATH
De esta manera su construcción no depende de algún camino concreto.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-22 05:21:12
A las personas que terminan aquí al buscar el equivalente de Gradle de la propiedad Maven maven.compiler.source
(o <source>1.8</source>
):
En construcción.gradle puedes lograr esto con
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
Vea la documentación de Gradle sobre esto.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-21 18:44:10
Hay una opción más a seguir. En tus tareas de gradle, puedes establecer la ruta de acceso jdk deseada. (Sé que esto es un tiempo desde que la pregunta fue publicada. Esta respuesta puede ayudar a alguien.)
Haz clic con el botón derecho en la implementación o en cualquier otra tarea y selecciona "Abrir configuración de ejecución de Gradle"..."
Luego vaya a "Java Home" y pegue la ruta de acceso de Java deseada.
Tenga en cuenta que la tarea gradle agregará bin. Tan no agregue el " bin " a la ruta.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-01 10:14:06
Como se ve en Gradle (complemento Eclipse)
Http://www.gradle.org/get-started
Gradle usa cualquier JDK que encuentre en tu ruta (para comprobarlo, usa java-version). Alternativamente, puede establecer la variable de entorno JAVA_HOME para que apunte al directorio de instalación del JDK deseado.
Si está utilizando este complemento Eclipse o Enide Studio 2014 , JAVA_HOME alternativo para usar (establecido en Preferencias) estará en versión 0.15, véase http://www.nodeclipse.org/history
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-04-01 06:38:13
Si estás usando linux y gradle wrapper puedes usar la siguiente solución.
Añadir ruta a local.archivo de propiedades:
javaHome=<path to JDK>
Agregue a su archivo de script gradlew:
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $DIR/local.properties 2>/dev/null
if ! [ -z "$javaHome" ]
then
JAVA_HOME=$javaHome
fi
En esta solución, cada desarrollador puede establecer su propia ruta JDK. File local.properties
no debe ser incluido en el sistema de control de versiones.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-07 20:04:19
He añadido esta línea en mi archivo GRADLE_HOME / bin / gradle -
export JAVA_HOME=/path/to/java/version
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-09 11:01:00
Estoy usando Gradle 4.2 . El valor predeterminado de JDK es Java 9. En los primeros días de Java 9, Gradle 4.2 se ejecuta en JDK 8 correctamente (no en JDK 9).
Establezco JDK manualmente así, en archivo %GRADLE_HOME%\bin\gradle.bat
:
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
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=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@rem VyDN-start.
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_144\
@rem VyDN-end.
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
@rem VyDN-start.
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_144\
@rem VyDN-end.
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\lib\gradle-launcher-4.2.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.launcher.GradleMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-29 04:00:52
Si estás ejecutando usando gradle wrapper, puedes ejecutar el comando con la ruta JDK como sigue
./gradlew -Dorg.gradle.java.home=/jdk_path_directory
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-26 09:10:08