Hi. This is the qmail-send program at mail.codehaus.org.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<[email protected]>:
Sorry, only subscribers may post. If you are a subscriber, please forward this 
message to [email protected] to get your new address included. 
(#5.7.2)

--- Below this line is a copy of the message.

Return-Path: <[email protected]>
Received: (qmail 8676 invoked by uid 89); 20 Jan 2011 07:32:09 -0000
Received: from unknown (HELO kontorsmtp2.one.com) (195.47.247.17)
  by mail.codehaus.org with (DHE-RSA-AES256-SHA encrypted) SMTP; 20 Jan 2011 
07:32:09 -0000
Received: from [192.168.217.35] (unknown [83.221.146.187])
        by kontorsmtp2.one.com (Postfix) with ESMTP id EF33C26C010B1
        for <[email protected]>; Thu, 20 Jan 2011 07:32:08 +0000 (UTC)
Subject: The build script's own dependency - "buildscript {}"
From: Thor Kummer <[email protected]>
To: [email protected]
Content-Type: text/plain; charset="UTF-8"
Date: Thu, 20 Jan 2011 08:32:08 +0100
Message-ID: <[email protected]>
Mime-Version: 1.0
X-Mailer: Evolution 2.28.3 
Content-Transfer-Encoding: 7bit

Hi

I'm new to gradle and I'm experimenting with a script to deploy our
database update SQL-scripts. For that the Gradle script needs the
PostgresQL driver. According to the documentation that should be specified
in the "buildscript" closure, like:


> 39.5. External dependencies for the build script
> If your build script needs to use external libraries, you can add them
> to the script's classpath in the build script itself. You do this
> using the buildscript() method, passing in a closure which declares
> the build script classpath. 
> 
> Example 39.4. Declaring external dependencies for the build script
> 
> build.gradle
> 
> buildscript {
>     repositories {
>         mavenCentral()
>     }
>     dependencies {
>         classpath group: 'commons-codec', name: 'commons-codec', version: 
> '1.2'
>     }
> }

I used the above and changed the dependency to the following:

> classpath group: 'postgresql', name: 'postgresql', version: '8.4-701.jdbc4'

Which is what mvnrepository.com specifies for Ike:

> <dependency org="postgresql" name="postgresql" rev="9.0-801.jdbc4"/>

I'm guessing the different attribute names are allowed synonymes.

The following is what I get when I run grdle:

> 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 jar file is correctly downloaded by Ike, I can see it in
~/.gradle/cache/postgresql/postgresql/jars/postgresql-8.4-701.jdbc4.jar
and it does contains /org/postgres/Driver.class.

When I drop the file into Gradle's lib directory the script works.

I've searched the mailinglist but didn't find any pointers.

Any hints are appreciated.

Regards

Thor

P.s: I'm pasting the whole script below just in case

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')
    def dbProjectEl = databaseVersions.project.find { it.@name as String == 
application }
    
    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 ->
      if(delegate.directory && delegate.name != '.svn' && 
includeDirs(delegate)) {
          delegate.eachFile {
              it.recurse(includeDirs, includeFiles, action)
          }
      } else if(includeFiles(delegate)) {
          action(delegate)
      }
    }
}        


class Db {
    String driver
    String host
    String port
    String name
    String user
    String password
    String url
    String versionScript
    String appliedScript
    
    Db(db, host) {
      this.driver = 'org.postgresql.Driver'
      this.host = host
      this.port = '5432'
      this.password = 'redacted'
      this.name = db.@name as String
      this.user = extractUser(db)
      this.url = "jdbc:postgresql://$host:$port/$name"
      this.versionScript = "${new Integer(db.@version as 
String).format("0000")}.sql"
      this.appliedScript = "${lookupVersion().format("0000")}.sql"
    }
    
    def extractUser(db) {
        def result = db.@user as String 
        if(! result) {
            def split = (db.@name as String).split(/_/)
            result = split.length > 1 ? split[1] : split[0]
        }
        return result
    }
    
    int lookupVersion() {
        def Sql sql = Sql.newInstance(url, user, password, driver)
        try {
          return sql.firstRow("SELECT version FROM version").version as int
        } catch(org.postgresql.util.PSQLException e) {
          if(e.message == 'ERROR: relation "version" does not exist') {
            return 9999
          }
          throw e
        }
    }

}



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to