Java Gradle 构建 - 无法导入 org.json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42433492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle build - not able to import org.json
提问by user619804
I have a problem where I'm trying to include org.json
as a dependency in my gradle/spring boot project. In my build.gradle I have
我有一个问题,我试图将其org.json
作为依赖项包含在我的 gradle/spring boot 项目中。在我的 build.gradle 我有
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.json:json:20141113")
}
But in the editor window it looks like IntelliJ is not able to import org.json - it's unable to find the package
但是在编辑器窗口中,IntelliJ 似乎无法导入 org.json - 无法找到包
What's weird is that I can run the gradle ‘build' task without errors in IntelliJ, and I can run
奇怪的是,我可以在 IntelliJ 中运行 gradle 'build' 任务而没有错误,而且我可以运行
./gradlew clean build && java -jar build/libs/MyApp-0.1.0.jar
and it works fine.
它工作正常。
Is this a ‘fat jar' problem? I'm not sure it is because org.json
is definitely not in my class path on the command line. Any advice appreciated.
这是一个“胖罐子”问题吗?我不确定这是因为org.json
绝对不在命令行上的类路径中。任何建议表示赞赏。
回答by David Miller
I was able to successfully download json in my gradle dependencies:
我能够在我的 gradle 依赖项中成功下载 json:
compile 'org.json:json:20171018'
回答by Mohsenne
As some mentioned, mvnrepositoryprovides snippet for different Build systems.
After you choose your desired version, in the middle of the page, select Gradle
as build system, copy and paste the snippet in your build.gradle
file, section dependencies
in your java project.
正如一些人提到的,mvnrepository为不同的构建系统提供了代码片段。选择您想要的版本后,在页面中间,选择Gradle
作为构建系统,将代码片段复制并粘贴到您的build.gradle
文件中,dependencies
在您的 Java 项目部分。
// https://mvnrepository.com/artifact/org.json/json
compile group: 'org.json', name: 'json', version: '20180813'