【问题标题】:Grails 3 - Gradle dependecies Mysql ConnectorGrails 3 - Gradle 依赖项 Mysql 连接器
【发布时间】:2016-01-27 22:18:30
【问题描述】:

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

【问题讨论】:

    标签: mysql gradle grails-3.0


    【解决方案1】:

    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
    

    【讨论】:

    • Ok stange 事情......如果我从命令行通过“grails run-app”运行应用程序,它正在使用“运行时”mysql:mysql-connector-java:5.1.37“,但是不在 Intellij IDEA EAP 15 中。你在使用任何 IDE 吗?
    • 我正在使用 IntelliJ IDEA 12.1.7。但是我将我的项目从 3.0.6 降级到 2.5.1,因为它有太多问题。它没有很好地(如果有的话)集成到 IDE 中,并且很多插件都造成了麻烦。当我在 3.0.6 上工作时,我使用命令行来运行和编译。
    • Intellij 说从 15 开始支持 grails 3,但我对 EAP 的体验不是很好。是的,添加插件也会带来麻烦。不可能毫无问题地添加像 font-awesome 这样的插件:(
    【解决方案2】:

    向 Intellij 添加本地 gradle 安装似乎可以解决问题。我认为包含的 gradle-wrapper 造成了麻烦。

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

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

    【讨论】:

    • 感谢以上提示。 Gradle 包装器肯定会导致这种行为。像魅力一样工作!
    • 与 gradle 2.11 的行为相同,更改为 2.14.1(当前)+ IntelliJ 15.0.2)并正常工作。下载 mysql 连接器 jar 时,ssl 握手似乎有问题。谢谢!
    猜你喜欢
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    相关资源
    最近更新 更多