Gradle/SQL - Building Stuck at 0%


(Jeffrey Effendy) #1

Hi,

I have the following code which the purpose is to find any sql script within the same folder and sub-folder of the build.gradle. So my code is as follows:

import groovy.sql.Sql
import groovy.io.FileType
  def getSqlFile() {
 def lst = []
 def dir = new File('/')
 dir.eachFileRecurse(FileType.FILES) {file ->
  fileName = file.toString()
  if(fileName.substring(fileName.length()-3, fileName.length()) == 'sql')
   lst << file
 }
 return lst
}
  def update() {
        def sql = Sql.newInstance("jdbc:mysql://localhost:3306/dummy", "root", "password", "com.mysql.jdbc.Driver")
    getSqlFile().each {sqlSyntax ->
        sql.execute(sqlSyntax)
    }
}
  repositories {
    mavenCentral()
}
  configurations {
    driver
}
  dependencies {
    driver group: 'mysql', name: 'mysql-connector-java', version: '5.1.18'
}
  URLClassLoader loader = GroovyObject.class.classLoader
configurations.driver.each {File file ->
    loader.addURL(file.toURL())
}
  task updateDB << {
    update()
}

When I run it, the build keeps at 0%. Is there any issue with it?


(Benjamin Muschko) #2

Can you run any SQL statement? Do you have long-running SQL statements? How many SQL files are you parsing? Should you use the text of the SQL file instead of the java.io.File when executing the SQL command?

I’d also check the return value of Sql.execute to see if the SQL execution was actually successful. I’d generally abstract that logic into a custom task. That’ll make it more readable and maintainable.


(Peter Niederwieser) #3

Scanning the whole filesystem will take a long time, too.