如何将guava lib添加到Intellij Idea中的Runtime ClassPath中



我正在尝试在Intellij Gradle项目中使用Guava,尽管我的代码编译,但在运行时我看到了此>

java.lang.noclassdeffounderror:com/google/common/collect/collect/ordering

我已经阅读了许多帖子,暗示Guava Lib在运行时不在类路径上。我已经通过使用system.getProperty(" java.class.path"(编写classPath来验证这一点,而guava lib不存在。

我已经尝试过(正如其他人所建议的那样(将文件夹或lib本身添加为带有scope = compile的模块依赖性。请参阅图像>

Intellij模块依赖项这也没有起作用。

这是项目中使用的libs>项目libs

关于这里发生的事情的任何建议非常感激。

我的build.gradle>

group 'EE'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
    mavenCentral()
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

它不包含我在项目库中添加的guava lib :: com.google.guava:guava:18.02

看来我错过了某个地方的重要一步。

guava的正式文档。

https://github.com/google/guava/wiki/useguavainyourbuild

将下面的行添加到您的build.gradle文件依赖项部分:

dependencies {
  compile group: 'com.google.guava', 
  name: 'guava', 
  version: '23.5-jre' # or 23.5-android for the Android flavor
}

最新更新