简体   繁体   English

Gradle构建找不到包'java.net.http'

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

I have set up a Java project in Intellij. 我已经在Intellij中设置了一个Java项目。 When I build my project within Intellij everything works fine. 当我在Intellij中构建项目时,一切正常。 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. 但是,当我尝试使用projects目录中的gradle build从命令行构建它时,Gradle抱怨没有找到java.net.http包。

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: 这是我的build.gradle文件:

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. 我对Gradle还是很陌生,想知道我是否缺少任何依赖声明。

java.net.http first appeared in Java 11 and you are trying to compile your code for Java 8 ( sourceCompatibility = 1.8 ). java.net.http最初出现在Java 11中,并且您正在尝试为Java 8编译代码( sourceCompatibility = 1.8 )。 You need to use Java 11+ for compilation (ie build using Java 11+) and for target language level ( sourceCompatibility ). 您需要使用Java 11+进行编译(即使用Java 11+进行构建)和目标语言级别( sourceCompatibility )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM