我已经使用grails 3.0.9
设置了一个grails应用程序现在我想添加mysql连接器以启动与mysql数据库的连接。
因此我在build.gradle中添加了一个条目,但gradle没有提取连接器。
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
classpath "org.grails.plugins:hibernate:4.3.10.5"
classpath "mysql:mysql-connector-java:5.1.37"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
}
version "0.1"
group "nexttext"
apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: "asset-pipeline"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:scaffolding"
runtime "org.grails.plugins:asset-pipeline"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
// Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'
console "org.grails:grails-console"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
不知道我做错了什么但得到了ClassNotFoundException。
答案 0 :(得分:2)
将runtime "mysql:mysql-connector-java:5.1.37"
添加到您的依赖项(在runtime "org.grails.plugins:asset-pipeline"
下)。然后编译它。这应该可以解决问题。
在我的Grails 3项目中,我没有连接器的类路径,所以我认为将其删除是保存的。
另外,不要忘记将这些行添加到dataSource下的application.yml中:
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
答案 1 :(得分:2)
向Intellij添加本地gradle安装似乎解决了这个问题。我认为包含的gradle-wrapper造成了麻烦。
因此,下载gradle 2.8并将其设置为在“设置”中使用 - >建立...... - >构建工具 - > Gradle解决了这个问题。
现在mysql连接器显示在External Libraries下 Gradle:mysql:mysql-connector-java:5.1.37