# PostgreSQL Dependency causes build time to EXPLODE upwards!

**URL:** https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441
**Category:** Old Forum Archive
**Created:** [October 15, 2014, 8:58pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441 "2014-10-15T20:58:00Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Kent\_Johnson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kent_johnson/32/826_2.png) [@Kent\_Johnson](https://discuss.gradle.org/u/Kent_Johnson)
#### Post date: [October 15, 2014, 8:58pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/1 "2014-10-15T20:58:00Z")

</div>

Why does including the ‘org.postgresql:postgresql:9.3-1102-jdbc41’ as a testCompile dependency make my project build time increase by 130 seconds or more?

In answer to the potential question as to why I picked the "testCompile"group, after reading the Gradle API documentation it stated the default behavior of the testCompile group is to include the dependency in the compile, runtime, and testRuntime groups, which is what I think I want. I need the JAR file at runtime for JDBC. Is the testCompile group an appropriate decision?

here is my build.gradle: buildscript {

ext {

springBootVersion = ‘1.1.8.RELEASE’

}

repositories {

mavenCentral()

}

dependencies {

classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”)

} }

apply plugin: ‘java’ apply plugin: ‘eclipse’ apply plugin: ‘idea’ apply plugin: ‘spring-boot’

jar {

baseName = ‘report.api’

version = ‘0.0.1-SNAPSHOT’ } sourceCompatibility = 1.8 targetCompatibility = 1.8

repositories {

mavenCentral() }

dependencies {

compile(“org.springframework.boot:spring-boot-starter-data-rest”)

compile(“org.springframework.boot:spring-boot-starter-aop”)

compile(“org.springframework.boot:spring-boot-starter-web”)

compile(“org.springframework.boot:spring-boot-starter-data-jpa”)

compile(“org.springframework.boot:spring-boot-starter-jdbc”)

compile(“org.springframework.boot:spring-boot-starter-actuator”)

testRuntime(“org.postgresql:postgresql:9.3-1102-jdbc41”)

testCompile(“org.springframework.boot:spring-boot-starter-test”) }

eclipse {

classpath {

containers.remove(‘org.eclipse.jdt.launching.JRE\_CONTAINER’)

containers ‘org.eclipse.jdt.launching.JRE\_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8’

} }

task wrapper(type: Wrapper) {

gradleVersion = ‘1.12’ }

---

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [October 15, 2014, 9:22pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/2 "2014-10-15T21:22:00Z")

</div>

If you need the PostgreSQL driver at **application** runtime then it should be added to the ‘runtime’ configuration, not ‘testRuntime’. If, however, PostgreSQL is only needed during test execution then ‘testRuntime’ is appropriate.

As far as build times increasing, try running your build with the ‘–profile’ flag. This will create a build execution report which should help identify which tasks in particular are taking a long time.

---

<div class="post-metadata">

### Author: ![Kent\_Johnson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kent_johnson/32/826_2.png) [@Kent\_Johnson](https://discuss.gradle.org/u/Kent_Johnson)
#### Post date: [October 15, 2014, 9:24pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/3 "2014-10-15T21:24:00Z")

</div>

I appreciate the quick reply! I am looking up what it means to add it to my runtime configuration. Can you point me in the right direction?

---

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [October 15, 2014, 9:27pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/4 "2014-10-15T21:27:00Z")

</div>

You can look at the [Gradle documentation](http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management) for an overview of all the default configurations added by the java plugin.

By “add it to the runtime configuration” I mean change the following line from

testRuntime(“org.postgresql:postgresql:9.3-1102-jdbc41”)

to

runtime(“org.postgresql:postgresql:9.3-1102-jdbc41”)

---

<div class="post-metadata">

### Author: ![Kent\_Johnson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kent_johnson/32/826_2.png) [@Kent\_Johnson](https://discuss.gradle.org/u/Kent_Johnson)
#### Post date: [October 15, 2014, 9:36pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/5 "2014-10-15T21:36:00Z")

</div>

Thanks for the clarification Mark.

As a follow up question, which I may repost, my runtime of the project increases by about 130 seconds after adding the PostgreSQL JDBC driver to the project. This is very strange and I’m not quite sure why this would happen. My project eventually runs and connects to a database though after taking up to five minutes at times.

Prior to adding “org.postgresql:postgresql:9.3-1102-jdbc41” to my dependencies my project would build in about five to ten seconds. After including the JDBC driver then my build and run times explode. Any clue as to why that would happen?

---

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [October 15, 2014, 9:43pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/6 "2014-10-15T21:43:00Z")

</div>

My only thought is it is something specific with Spring Data. My guess is it wasn’t actually attempting to configure and connect to a datasource without a JDBC driver on the classpath. Also, when you say your “build” is taking a long time, do you mean the build or just the Spring Boot startup. For example, do you see the delay when simply running ‘gradlew build’ or is this only when running the ‘bootRun’ task?

---

<div class="post-metadata">

### Author: ![Kent\_Johnson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kent_johnson/32/826_2.png) [@Kent\_Johnson](https://discuss.gradle.org/u/Kent_Johnson)
#### Post date: [October 15, 2014, 9:48pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/7 "2014-10-15T21:48:00Z")

</div>

Interestingly enough I see the delay both when doing ‘./gradlew build’ as well as when running the ‘bootRun’ task. I profiled the task and found that it is my ‘test’ task that is taking so long.

My entire build took 1:35.39s and the test task took 1:34.81s. There are no active tests in my code that I am aware of. I had one before I commented its code out.

I, too, wondered if it is something with Spring Data. I have no idea how to determine whether that is the cause though. It would be nice to know what to look at next. It seems like the main option is to ask the Spring Data team if they could shed some light on the issue.

---

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [October 15, 2014, 9:57pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/8 "2014-10-15T21:57:00Z")

</div>

My guess is something is timing out, retrying, etc when attempting to construct a datasource connection. It is odd that it is doing that when running the test task despite you not having any tests declared. The Spring forums may be of better help, I’m quite certain this has nothing to do with Gradle specifically. Additionally, you might try cranking up the [logging](http://docs.spring.io/spring-boot/docs/1.1.8.RELEASE/reference/htmlsingle/#boot-features-logging) which might give you more insight specifically where in the Spring context initialization process your application is getting hung up on.

---

<div class="post-metadata">

### Author: ![Kent\_Johnson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kent_johnson/32/826_2.png) [@Kent\_Johnson](https://discuss.gradle.org/u/Kent_Johnson)
#### Post date: [October 15, 2014, 10:14pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/9 "2014-10-15T22:14:00Z")

</div>

I’ll check into it. It is wasting HOURS of my time.

---

<div class="post-metadata">

### Author: ![Kent\_Johnson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kent_johnson/32/826_2.png) [@Kent\_Johnson](https://discuss.gradle.org/u/Kent_Johnson)
#### Post date: [October 15, 2014, 10:43pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/10 "2014-10-15T22:43:00Z")

</div>

I found out that my testing task is what exploded.

I ended up excluding the test task whenever I built the project. The ballooning of the build time happened only after adding the JDBC driver to the dependencies, which causes me to think there is something unexpected behavior happening with the test task of Gradle and the JDBC driver.

Next I’ll have to try having a vanilla Gradle project and adding the JDBC driver as a runtime dependency to see if the same thing happens.

Do you still think it could be an issue with Spring Data? I have the same results whether I am connected to my VPN or not, which I have to be in order to get connected to my database.

---

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [October 15, 2014, 10:54pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/11 "2014-10-15T22:54:00Z")

</div>

If you change the configuration of the Postgres dependency from ‘testRuntime’ to ‘runtime’ and then run the ‘bootRun’ task do you still get the long build time?

---

<div class="post-metadata">

### Author: ![Kent\_Johnson](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kent_johnson/32/826_2.png) [@Kent\_Johnson](https://discuss.gradle.org/u/Kent_Johnson)
#### Post date: [October 16, 2014, 2:22pm UTC](https://discuss.gradle.org/t/postgresql-dependency-causes-build-time-to-explode-upwards/7441/12 "2014-10-16T14:22:00Z")

</div>

Yes, I still get the long build time. I turned on Hibernate logging at the DEBUG level and found the reason the program is hanging. There is a statement that says “Unexpected error trying to gauge level of JDBC REF\_CURSOR support : null” which I have no idea what that means yet. I already posted to the PostgreSQL bug mailing list, will be posting to the Hibernate forums, and will be posting a question to the StackOverflow Spring Boot tag.

The full log from ‘./gradlew bootRun’ to when the hanging starts is in this paste: [http://pastebin.com/CAjSyQw9](http://pastebin.com/CAjSyQw9)
