[GRADLE-1354] Groovy's Sql doesn't see a database driver class specified in "buildscripts" Created: 26/Jan/11 Updated: 10/Feb/17 Resolved: 10/Feb/17 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | 0.9.1 |
Fix Version/s: | None |
Type: | Bug | ||
Reporter: | Thor Kummer | Assignee: | Unassigned |
Resolution: | Won't Fix | Votes: | 2 |
Description |
I specified the PostgresQL driver in the "buildsscripts" closure, as in Example 39.4. "Declaring external dependencies for the build script" buildscript { dependencies { classpath group: 'postgresql', name: 'postgresql', version: '8.4-701.jdbc4' } } Gradle -s prints > 15:29:59-tk@tk:~/workspace/b-one-crm> gradle -s -b build.gradle.groovy deployDb > :deployDb > > FAILURE: Build failed with an exception. > > * Where: > Build file '/home/tk/workspace/b-one-crm/build.gradle.groovy' line: 100 > > * What went wrong: > Execution failed for task ':deployDb'. > Cause: java.lang.ClassNotFoundException: org.postgresql.Driver > > * Try: > Run with -S option to get the full (very verbose) stacktrace. > > * Exception is: > org.gradle.api.tasks.LocationAwareTaskExecutionException: Build file '/home/tk/workspace/b-one-crm/build.gradle.groovy' line: 100 > Execution failed for task ':deployDb'. > at org.gradle.api.internal.tasks.DefaultTaskExecuter.executeActions(DefaultTaskExecuter.java:63) > at org.gradle.api.internal.tasks.DefaultTaskExecuter.execute(DefaultTaskExecuter.java:41) > at org.gradle.api.internal.project.taskfactory.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:32) > at org.gradle.api.internal.project.taskfactory.ExecutionShortCircuitTaskExecuter.execute(ExecutionShortCircuitTaskExecuter.java:50) > at org.gradle.api.internal.tasks.SkipTaskExecuter.doExecute(SkipTaskExecuter.java:57) > at org.gradle.api.internal.tasks.SkipTaskExecuter.execute(SkipTaskExecuter.java:35) > at org.gradle.api.internal.tasks.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:32) > at org.gradle.api.internal.AbstractTask.execute(AbstractTask.java:231) > at org.gradle.execution.DefaultTaskGraphExecuter.executeTask(DefaultTaskGraphExecuter.java:167) > at org.gradle.execution.DefaultTaskGraphExecuter.doExecute(DefaultTaskGraphExecuter.java:160) > at org.gradle.execution.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:78) > at org.gradle.execution.TaskNameResolvingBuildExecuter.execute(TaskNameResolvingBuildExecuter.java:161) > at org.gradle.execution.DelegatingBuildExecuter.execute(DelegatingBuildExecuter.java:54) > at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:153) > at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:107) > at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:75) > at org.gradle.launcher.Main.execute(Main.java:93) > at org.gradle.launcher.Main.main(Main.java:42) > at org.gradle.launcher.GradleMain.main(GradleMain.java:49) > Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.ClassNotFoundException: org.postgresql.Driver > at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:445) > at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:432) > at org.gradle.api.internal.tasks.DefaultTaskExecuter.executeActions(DefaultTaskExecuter.java:55) > ... 18 common frames omitted > Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver > at Db.lookupVersion(/home/tk/workspace/b-one-crm/build.gradle.groovy:100) > at Db$lookupVersion.callCurrent(Unknown Source) > at Db.<init>(/home/tk/workspace/b-one-crm/build.gradle.groovy:87) > at build_gradle_groovy_efff0db1333cb234a677f1a67e718f98$_run_closure1_closure7.doCall(/home/tk/workspace/b-one-crm/build.gradle.groovy:25) > at build_gradle_groovy_efff0db1333cb234a677f1a67e718f98$_run_closure1.doCall(/home/tk/workspace/b-one-crm/build.gradle.groovy:23) > ... 21 common frames omitted > > BUILD FAILED > > Total time: 2.024 secs The buildscript is pasted below import groovy.sql.Sql import java.text.* mixin() def dbHost = 'db.example.com' def application = 'crm' buildscript { repositories { mavenCentral() } dependencies { classpath group: 'postgresql', name: 'postgresql', version: '8.4-701.jdbc4' }} task deployDb << { def databaseVersions = new XmlSlurper().parse('database-versions.xml') dbProjectEl.database.each { database -> Db db = new Db(database, dbHost) println "database-scripts/$db.name, db.appliedScript: $db.appliedScript, db.versionScript: $db.versionScript" ("database-scripts/$db.name" as File).listFiles().sort { it.name }.each { script -> if(script.name.endsWith('.sql') && db.appliedScript < script.name && script.name <= db.versionScript) { println "Updating script $script" ant.exec(executable: './x', failonerror: 'true') { arg(line: "$db.host $db.user $db.name $script") } println "successfully deploy database script $script" def mixin() { Number.metaClass.format << { fmt -> new DecimalFormat(fmt).format(delegate) }Date.metaClass.format << { fmt -> new SimpleDateFormat(fmt).format(delegate) }File.metaClass.recurse << { Closure include, Closure action -> delegate.recurse(include, include, action) } File.metaClass.recurse << { Closure includeDirs, Closure includeFiles, Closure action -> } else if(includeFiles(delegate)) { action(delegate) } } class Db { Db(db, host) { def extractUser(db) { return result int lookupVersion() { catch(org.postgresql.util.PSQLException e) { throw e } See mailing list thread [gradle-user] Question about the buildscripts own dependencies - "buildscript" for more details. |
Comments |
Comment by Steinar Haugen [ 11/Aug/11 ] |
A work-around that works for us is // configure additional 3rd party libraries that we need to add to the gradle runtime classpath repositories { mavenCentral() } configurations { gradleRuntime {transitive = false} } dependencies { gradleRuntime JCONN, DBUNIT } URLClassLoader loader = GroovyObject.class.classLoader configurations.gradleRuntime.each { File file -> loader.addURL(file.toURL()) logger.info "Added jar to gradle runtime: $file" } What's new in milestone 4 for us (compared with milestone 1, which we recently upgraded from) is that we didn't need the buildscript dependencies when doing this in ms1, but had to add normal buildscript dependencies in addition to this work-around hack in ms4. |
Comment by Benjamin Muschko [ 15/Nov/16 ] |
As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub. We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to. Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:
We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle! |
Comment by Benjamin Muschko [ 10/Feb/17 ] |
Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved. |