我如何告诉Gradle使用特定的JDK版本? [英] How do I tell Gradle to use specific JDK version?

查看:5522
本文介绍了我如何告诉Gradle使用特定的JDK版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



场景:


  • 我有一个使用gradle构建的应用程序

  • 应用程序使用JavaFX



想要使用一个变量(定义为每个开发人员机器),它指向一个JDK的安装,它将用于构建整个应用程序/测试/ ...


我想过要有 gradle.properties 文件,定义变量。类似于

  JAVA_HOME_FOR_MY_PROJECT =<我想要的JDK的路径> 

我不想要的东西


  • JAVA_HOME 到所需的JDK



I可以忍受很多建议:


  • 一个解决方案,它定义了一个系统环境变量,我可以在我的build.gradle脚本中检查

  • 在gradle.properties中定义的变量
  • 仅为构建上下文重写JAVA_HOME变量(类似于使用JAVA_HOME =< ;我的特殊JDK路径定义在其他地方定义>

  • 其他我没想过的东西



问题:


  • 如何连线一个变量(如何定义变量, c $ c> gradle.properties ,系统环境变量,...)到构建过程中?


我有多个JDK7可用,需要指向特殊版本(最低JDK_u版本)。



任何答案都是appr eciated,我感谢每一个提示正确的方向。

解决方案

两种方式


  1. .gradle 中的 gradle.properties 目录中的 HOME_DIRECTORY 设置 org.gradle.java.home = / path_to_jdk_directory


  2. $ li $ build.gradle

      compileJava.options.fork = true 
    compileJava.options.forkOptions.executable = / path_to_javac


    ol>

    I can't figure out to get this working.

    Scenario:

    • I have an application built with gradle
    • The application uses JavaFX

    What I want

    • Use a variable (defined per developer machine) which points to an installation of a JDK which will be used for building the whole application / tests / ...

    I thought about having the gradle.properties file, defining the variable. Something like

    JAVA_HOME_FOR_MY_PROJECT=<path to my desired JDK>
    

    What I don't want

    • point JAVA_HOME to the desired JDK

    I could live with many suggestions:

    • a solution that defines a system environment variable which I'm able to check in my build.gradle script
    • a variable defined in gradle.properties
    • overriding the JAVA_HOME variable only for the build context (something like use JAVA_HOME=<my special JDK path defined somewhere else defined>)
    • something else I didn't think about

    Question:

    • How to wire a variable (how ever defined, as variable in the gradle.properties, system environment variable, ...) to the build process?

    I have more than one JDK7 available and need to point to a special version (minimum JDK_u version).

    Any answer is appreciated and I'm thankful for every hint to the right direction.

    解决方案

    Two ways

    1. In gradle.properties in the .gradle directory in your HOME_DIRECTORY set org.gradle.java.home=/path_to_jdk_directory

    2. In your build.gradle

      compileJava.options.fork = true
      compileJava.options.forkOptions.executable = /path_to_javac
      

    这篇关于我如何告诉Gradle使用特定的JDK版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆