数据库
首页 > 数据库> > java-具有IntelliJ的Gradle不会将PostgreSQL JDBC作为依赖项加载

java-具有IntelliJ的Gradle不会将PostgreSQL JDBC作为依赖项加载

作者:互联网

我正在尝试为我的下一个项目设置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 ...
}

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

 .

不知何故,Gradle正在下载,而IntelliJ则将jooq和guava识别为我的依赖项的一部分,但未显示postgresql.因此,在执行此操作时(使用Guava,这是从Gradle加载的依赖项):

List<String> stringList = Lists.newArrayList();

这将失败,并显示ClassNotFoundException:

Class.forName("org.postgresql.Driver").newInstance();

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

解决方法:

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

标签:maven,intellij-idea,gradle,java
来源: https://codeday.me/bug/20191121/2054474.html