2015-10-19 71 views
0

我使用的摇篮2.7在Windows 7我想一旦运行运行我的Gradle Liquibase插件时,我在哪里放置MySql JAR依赖项?

gradle build 

所以我有下面的代码在我的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 

,但我得到运行我Liquibase插件以下错误

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 

鉴于司机在我的类路径(见上述“‘的mysql:mysql的连接器的Java:5.1.36’”在depencney列表),在那里它需要去让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 

,但得到下面的错误...

$ 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 

回答

6

望着liquibase插件源,它看起来像你会需要添加您的依赖到您的buildscript

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'mysql:mysql-connector-java:5.1.36' 
    } 
} 
+0

我试过这个,但它失败。更高版本的gradle是否支持“buildscript”语法?我把你的建议输出到我的问题中。 – Dave

+0

将buildscript部分移至build.gradle文件的最顶端。 – Ethan

+0

谢谢,这正是我正在寻找的! – Jordan

相关问题