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?