Gradle build can't find the package 'java.net.http'

Plebo13 :

I have set up a Java project in Intellij. When I build my project within Intellij everything works fine. But when I try to build it from the command line using gradle build in the projects directory, Gradle complains about not finding the java.net.http package.

This is an example if the imports I use in one of my classes:

import com.google.common.base.Joiner;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.Reference;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import org.apache.commons.math3.stat.descriptive.rank.Median;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

And this is my build.gradle file:

plugins {
    id 'java'
}

group 'DatabaseUpdater'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'org.mongodb:mongo-java-driver:2.12.3'
    compile 'dev.morphia.morphia:core:1.5.3'
    compile 'com.google.guava:guava:28.0-jre'
    compile 'org.jsoup:jsoup:1.12.1'
    compile group: 'org.apache.commons', name: 'commons-math3', version: '3.0'
}

I am quite new to Gradle and wondering if I am missing any dependency declaration or so.

madhead :

java.net.http first appeared in Java 11 and you are trying to compile your code for Java 8 (sourceCompatibility = 1.8). You need to use Java 11+ for compilation (i.e. build using Java 11+) and for target language level (sourceCompatibility).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=161817&siteId=1