问题
When we set path to java libraries, we just write something like this:
compile('ch.qos.logback:logback-classic:1.0.13')
There is no any path information here, I don't bother if JAR will be located on drive C:
on drive D:
or in Linux root /
Let it remains so.
And now I want to set JDK version. I wish to be able to change this version easily and portable without setting any paths, relative to my machine.
Is this possible?
UPDATE
Apparently, even Ant can this: https://stackoverflow.com/a/11551770/258483
回答1:
Java has no concept of libraries or versions. In Java, there is no standard way to tell the JVM that you are using version 3.0.5 of Hibernate, and there is no standard way to say that foo-1.0.jar depends on bar-2.0.jar. This has led to external solutions often based on build tools.
This is taken from Gradle's dependency management Doc.
So this is where gradle dependency management is done, by dependency they mean Project's dependencies on external packages. Something called Separation of Concern. If you want to declare which Jdk your project should be using (jdk here is the compiler (the javac program) which is doing something thats logically different than what Project's dependencies do) the dependency block is not the right place to put it in.
As for how to declare the your custom jdk path to use:
Two ways
In
gradle.properties
in the.gradle
directory in yourHOME_DIRECTORY
setorg.gradle.java.home=/path_to_jdk_directory
The gradle.properties can be defined at project level too, see gradle.org/docs/current/userguide/build_environment.htmlIn your
gradle.build
compileJava.options.fork = true compileJava.options.forkOptions.executable = /path_to_javac
来源:https://stackoverflow.com/questions/35911416/how-to-set-jdk-version-in-gradle-project-without-explicit-jdk-path