运行我的Gradle Liquibase插件时,我在哪里放置MySql JAR依赖项?

Dav*_*ave 0 mysql dependencies liquibase gradle

我在Windows 7上使用Gradle 2.7.我想在运行时运行我的Liquibase插件

gradle build
Run Code Online (Sandbox Code Playgroud)

所以我在build.gradle文件中有以下代码

// 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
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误

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
Run Code Online (Sandbox Code Playgroud)

鉴于驱动程序在我的类路径中(请参阅依赖项列表中的上述"'mysql:mysql-connector-java:5.1.36'"),需要在哪里让Liquibase识别它?

编辑:根据建议,我尝试了以下

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
Run Code Online (Sandbox Code Playgroud)

但得到以下错误......

$ 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
Run Code Online (Sandbox Code Playgroud)

Eth*_*han 8

查看liquibase插件源代码,看起来您需要将依赖项添加到您的buildscript中

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'mysql:mysql-connector-java:5.1.36'
    }
}
Run Code Online (Sandbox Code Playgroud)