Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle with IntelliJ not loading PostgreSQL JDBC as a dependency

I am trying to setup IntelliJ alongwith Gradle and JOOQ for my next project. As of now, this is how my Gradle file looks like:

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 ...
}

And this is how my external dependencies (in IntelliJ) show up:

External dependency pane in IntelliJ .

Somehow, Gradle is downloading and IntelliJ is recognizing the jooq and guava as part of my dependencies, but postgresql does not show up. So, while doing this works (using Guava, a dependency loaded from Gradle):

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

This fails with a ClassNotFoundException:

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

While doing a ./gradlew build, I have seen gradle output the fact that it did download thr postgresql-9.1-901 jar from Maven Central, but I don't know where it keeps it. Any help is greatly appreciated.

like image 695
Rohan Prabhu Avatar asked Apr 30 '14 04:04

Rohan Prabhu


People also ask

Does JDBC work with PostgreSQL?

The PostgreSQL JDBC Driver allows Java programs to connect to a PostgreSQL database using standard, database independent Java code. pgJDBC is an open source JDBC driver written in Pure Java (Type 4), and communicates in the PostgreSQL native network protocol.


1 Answers

Apparently, I really need to RTFM. I hadn't refreshed the dependencies from the Gradle tool window in IntelliJ after making changes to the Gradle script. Got it from here: https://www.jetbrains.com/idea/webhelp/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html

like image 147
Rohan Prabhu Avatar answered Sep 21 '22 16:09

Rohan Prabhu