当 运行 我的 Gradle Liquibase 插件时,我将 MySql JAR 依赖项放在哪里?
When running my Gradle Liquibase plugin, where do I put the MySql JAR dependency?
我在 Windows 7 上使用 Gradle 2.7。我想在 运行ning
上 运行 我的 Liquibase 插件
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
但我收到以下错误
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-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
但出现以下错误...
$ 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
查看 liquibase 插件源,您似乎需要将依赖项添加到构建脚本中
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'mysql:mysql-connector-java:5.1.36'
}
}
我在 Windows 7 上使用 Gradle 2.7。我想在 运行ning
上 运行 我的 Liquibase 插件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
但我收到以下错误
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-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
但出现以下错误...
$ 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
查看 liquibase 插件源,您似乎需要将依赖项添加到构建脚本中
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'mysql:mysql-connector-java:5.1.36'
}
}