繁体   English   中英

Grails 3-Gradle依赖Mysql Connector

[英]Grails 3 - Gradle dependecies Mysql Connector

我已经使用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。

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

在Intellij中添加本地gradle安装似乎可以解决该问题。 我认为附带的gradle-wrapper造成了麻烦。

因此,下载gradle 2.8并将其设置为在Settings-> Build ...-> Build Tools-> Gradle中使用即可解决该问题。

现在,mysql连接器显示在“外部库Gradle”下:mysql:mysql-connector-java:5.1.37

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM