当前位置: 动力学知识库 > 问答 > 编程问答 >

When running my Gradle Liquibase plugin, where do I put the MySql JAR dependency?

问题描述:

I'm using Gradle 2.7 on Windows 7. I want to run my Liquibase plugin upon running

gradle build

So I have the below code in my build.gradle file

// In this section you declare the dependencies for your production and test code

dependencies {

// The production code uses the SLF4J logging API at compile time

compile (

'commons-beanutils:commons-beanutils:1.8.3',

'commons-collections:commons-collections:3.2.1',

'org.apache.commons:commons-dbcp2:2.1.1',

'commons-lang:commons-lang:2.6',

'commons-logging:commons-logging:1.2',

'org.apache.commons:commons-pool2:2.4.2',

'org.directwebremoting:dwr:3.0.0-RELEASE',

'org.apache.httpcomponents:httpclient:4.5.1',

'org.codehaus.jackson:jackson-core-asl:1.9.13',

'org.codehaus.jackson:jackson-mapper-asl:1.9.13',

'net.sf.json-lib:json-lib:2.4:jdk15',

'jstl:jstl:1.2',

'log4j:log4j:1.2.15',

'joda-time:joda-time:2.8.2',

'org.mybatis:mybatis:3.3.0',

'org.mybatis:mybatis-spring:1.2.3',

'mysql:mysql-connector-java:5.1.36',

'org.springframework:spring-aop:4.2.1.RELEASE',

'org.springframework:spring-aspects:4.2.1.RELEASE',

'org.springframework:spring-beans:4.2.1.RELEASE',

'org.springframework:spring-context:4.2.1.RELEASE',

'org.springframework:spring-context-support:4.2.1.RELEASE',

'org.springframework:spring-core:4.2.1.RELEASE',

'org.springframework:spring-expression:4.2.1.RELEASE',

'org.springframework:spring-instrument:4.2.1.RELEASE',

'org.springframework:spring-instrument-tomcat:4.2.1.RELEASE',

'org.springframework:spring-jdbc:4.2.1.RELEASE',

'org.springframework:spring-jms:4.2.1.RELEASE',

'org.springframework:spring-messaging:4.2.1.RELEASE',

'org.springframework:spring-test:4.2.1.RELEASE',

'org.springframework:spring-tx:4.2.1.RELEASE',

'org.springframework:spring-web:4.2.1.RELEASE',

'org.springframework:spring-webmvc:4.2.1.RELEASE'

)

...

liquibase {

activities {

main {

File propsFile = new File("${project.rootDir}/src/main/resources/liquibase.properties")

Properties properties = new Properties()

properties.load(new FileInputStream(propsFile))

changeLogFile 'src/main/resources/db.changelog-1.0.xml'

url 'jdbc:mysql://localhost:3306/my_db'

username 'username'

password 'poassword'

}

runList = "main"

}

}

testClasses.dependsOn update

but I get the following error

For more information, use the --logLevel flag

:update FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':update'.

> liquibase.exception.LiquibaseException: Unexpected error running Liquibase: java.lang.RuntimeException: Cannot find database driver: com.mysql.jdbc.Driver

Given that the driver is in my classpath (see the above "'mysql:mysql-connector-java:5.1.36'" in the depencney list), where does it need to go to get Liquibase to recognize it?

Edit: Per the suggestion, I tried the below

buildscript {

repositories {

mavenCentral()

}

dependencies {

classpath("mysql:mysql-connector-java:5.1.36")

}

}

liquibase {

activities {

main {

File propsFile = new File("${project.rootDir}/src/main/resources/liquibase.properties")

Properties properties = new Properties()

properties.load(new FileInputStream(propsFile))

changeLogFile 'src/main/resources/db.changelog-1.0.xml'

url 'jdbc:mysql://localhost:3306/xxx_db'

username 'xxx'

password 'xxx'

}

runList = "main"

}

}

testClasses.dependsOn update

but got the below error ...

$ gradle build

FAILURE: Build failed with an exception.

* Where:

Build file 'C:\Users\myuser\Dropbox\cb_workspace\xxmyproject\build.gradle' line: 126

* What went wrong:

Could not compile build file 'C:\Users\myuser\Dropbox\cb_workspace\xxmyproject\build.gradle'.

> startup failed:

build file 'C:\Users\myuser\Dropbox\cb_workspace\xxmyproject\build.gradle': 126: all buildscript {} blocks must appear before any plugins {} blocks in the script

See https://docs.gradle.org/2.7/userguide/plugins.html#sec:plugins_block for information on the plugins {} block

@ line 126, column 1.

buildscript {

^

1 error

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.657 secs

网友答案:

Looking at the liquibase plugins source, it looks like you will need to add your dependency to your buildscript

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'mysql:mysql-connector-java:5.1.36'
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: