带有 IntelliJ 的 Gradle 未将 PostgreSQL JDBC 作为依赖项加载

Roh*_*bhu 5 java intellij-idea gradle maven

我正在尝试为我的下一个项目设置 IntelliJ 以及 Gradle 和 JOOQ。到目前为止,这就是我的 Gradle 文件的样子:

apply plugin: 'java'
apply plugin: 'jooq'

sourceCompatibility = 1.5
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

dependencies {
    compile 'org.jooq:jooq:3.1.0'
    compile 'com.google.guava:guava:14.0'
    compile 'postgresql:postgresql:9.1-901-1.jdbc4'
}

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        classpath 'postgresql:postgresql:9.1-901-1.jdbc4'
        classpath 'com.github.ben-manes:gradle-jooq-plugin:0.5'
    }
}

jooq {
   ... snip ...
}
Run Code Online (Sandbox Code Playgroud)

这就是我的外部依赖项(在 IntelliJ 中)的显示方式:

IntelliJ 中的外部依赖项窗格 .

不知何故,Gradle 正在下载,IntelliJ 将 jooq 和 guava 识别为我的依赖项的一部分,但 postgresql 没有出现。因此,在执行此操作时(使用 Guava,从 Gradle 加载的依赖项):

List<String> stringList = Lists.newArrayList();
Run Code Online (Sandbox Code Playgroud)

这失败了ClassNotFoundException

Class.forName("org.postgresql.Driver").newInstance();
Run Code Online (Sandbox Code Playgroud)

在执行 . 时./gradlew build,我看到 gradle 输出了它确实从 Maven Central 下载了 postgresql-9.1-901 jar 的事实,但我不知道它保存在哪里。任何帮助是极大的赞赏。

Roh*_*bhu 5

显然,我真的需要 RTFM。在对 Gradle 脚本进行更改后,我没有从 IntelliJ 中的 Gradle 工具窗口刷新依赖项。从这里得到它:https : //www.jetbrains.com/idea/webhelp/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html