Gradle build project with specific jdk - java

I am having Grails project (grails 2.3.11) with multiple Grails plugins. One main Grails project in addition of some user defined Grails plugins and core Java project creates a complete application. So far, these projects are build using Ant builder. Recently upgraded build process to use Gradle.
Problem with gradle process is that some project needs to be build with jdk 1.7 and some to be build with jdk 1.8. In order to fix it, I have set java_home to point to jdk 1.7. Then created gradle.properties file in project directories which needs code to be build with jdk 1.8. Have set property org.gradle.java.home to point to jdk 1.8. Now when I print java_home value from such project I found that it is still picking jdk 1.7 (the one set as environment variable).
Here my gradle compileJava task:
compileJava {
options.encoding = 'UTF-8'
def env = System.getenv("JAVA_HOME")
println "Compile Java: JAVAHOME = ${env}"
dependsOn ':core:updateversiondotjava'
logging.captureStandardOutput LogLevel.DEBUG
}
Projects build with 1.7 are all Grails project and Grails user defined plugins. Reason to build them with 1.7 is to avoid grails version upgrade. Because grails 2.3.x or lower are not supporting Java 1.8.
Can anyone please guide me where I am doing wrong?

I recall Grails 2.3.11 running on Java 8 in my testing. Early versions of Grails 2.3 did not run on Java 8. I understand the official support started with 2.4.x but have you tried Java 8 with your 2.3.11 application?

Related

Java Gradle Error : Your build is currently configured to use Java 17.0.2 and Gradle 7.3.1

We are attempting to upgrade our project to use Java 17 with a compatible Gradle. We expect that Java 17.0.2 and Gradle 7.3.1 should be compatible per Gradle Compatibility Matrix
However, when we attempt to run our project we get the following error :
Unsupported Java.
Your build is currently configured to use Java 17.0.2 and Gradle 7.3.1.
Possible solution:
- Use Java 16 as Gradle JVM: Open Gradle settings
- Open Gradle wrapper settings, change `distributionUrl` property to use compatible Gradle version and reload the project
We are using IntelliJ with Gradle JVM set to : openjdk-17 version 17.0.2 and Project SDK set to : openjdk-17 version 17.0.2
We are using Gradle distribution url : distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
It appears that these should be compatible does anyone know what could be causing this?

How can i change the Gradle Version in InteliJ?

I have the Error: "Found invalid Gradle JVM configuration"
"JDK 17.0.1 isnĀ“t compatible with gradle 7.1. Please fix JAVA_HOME enviroment variable"
Im not sure why it says gradle 7.1. The gradle Version i have is 7.4.2. This version should work with JDK 17
Take a look at the gradle-wrapper.properties file in the ./gradle/wrapper directory.
In the file, you can define the distribution URL from which Gradle is loaded. For example:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
As far as I know, IntelliJ adopts the version.
According to the Gradle documentation, Gradle 7.3 is the first Gradle version that supports JDK 17. You could try that one.

How to create a jar file with gradle shadowJar that works on java 11

I have java version 15 on my PC, and when I create a jar file with gradle using gradle shadowJar, the jar file does not run on my mac which has java version 11.
Here is my project setting, I have already changed the version to java 11 on the gradle setting page.
Here is the error on my mac:
Is there a quick way to fix this?
I assume you are building on the command line and not through IntelliJ. Otherwise, I don't know what is wrong. But even if you are not, you should still configure Java compatibility to make your build more independent of the local environment.
Gradle will by default build with the same JDK as you run Gradle with. You can verify what version that is by gradlew --version on the command line. Normally you can set it with the environment variable JAVA_HOME.
In order to ensure your build is compatible with Java 11, no matter what version you use to run Gradle with, you have a few options.
Firstly, you can specify a toolchain. This will make Gradle automatically download a compatible version of the JDK if you are not already using one. Only available since Gradle 6.7.
// Groovy DSL. Gradle 6.7+
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
You can also specify a release flag. This will instruct the current JDK, even if you are running with Java 15, to make the build compatible with an earlier version. Only available since Gradle version 6.6.
// Groovy DSL. Gradle 6.6+
compileJava {
options.release = 11
}
Lastly, if you are on an older version of Gradle, you can specify a source and target compatibility. This is not as good as the previous options as it doesn't ensure that you are using only Java 11 compatible APIs - only the bytecode will be compatible with Java 11.
// Groovy DSL. Any version of Gradle (but not as safe)
compileJava {
sourceCompatibility = 11
targetCompatibility = 11
}

How to make a Grails Maven project use Java 1.7 in GGTS?

I have a Grails 2.3.7 project which should use Java 1.7.
I am using the Spring GGTS IDE as development tool and it is configured to use a Java 1.7 JDK.
I created the project in GGTS and changed the source and target level to 1.7.
Then I generate a maven pom file with the create-pom command.
So far so good. The project is linked to use a JRE System Library of version 1.7.
Then I change the project to be a Maven project in GGTS. What happens now is that in GGTS, the project changes the JRE System Library to become of version 1.6. I can manually switch it back to a java 1.7 library but every time I do a "Maven update project", the 1.6 library is back.
What am I doing wrong?
By removing the jre 1.6 as installed jre from GGTS, the project will use my jre 1.7. But in the list of linked dependencies it is still labeled JRE System Library [Java-SE 1.6] even though it points to my 1.7 instance. This solved my build-issues even though it still looks wrong.

Compiling Android project with JDK 1.7

My Android project is set up to use Maven, so I imported into IntelliJ from the pom.xml file. The compiler settings in IntelliJ are correctly pointing to 1.7, but when I try to compile I get:
Error: java: javacTask: source release 1.7 requires target release 1.7
My settings for the maven compiler plugin has both source and target set to this, so that's not the problem. However, in the module settings I see that my module is using
Maven Android API 19 Platform (java version "1.6.0_37")
If I try changing this manually in IntelliJ when I open my project after closing it it gets set back. I think that it has something to do with the android-maven-plugin, but I don't see where to force it to use java 1.7.
There is nothing in the Android Maven Plugin that forces Java 6. It must have to do IntelliJ and its Maven integration somehow. Or some other related configuration.

Categories