emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[QZ1] build.gradle, sourceCompatibility and targetCompatibility question #204

Closed Wang-Matthew closed 1 year ago

Wang-Matthew commented 2 years ago

For the instructions in 0.1 of the textbook it says to open build.gradle and make sure sourceCompatibility and targetCompatibility are set to java version 17.

I looked through the IntelliJ documentation which told me those were historical options for the Java compiler and said you could also set them with the JavaCompile task. I used this code:

tasks.withType(JavaCompile) {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

instead and I was wondering if this was acceptable because I was getting errors when I wrote

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

as the textbook instructs.

jdchoi77 commented 2 years ago

@Wang-Matthew thanks for pointing this out; for simplicity, it'd be better to use compileJava instead as follows:

compileJava {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

I updated the build.gradle so please take a look.