Grails 3 - Gradle dependecies Mysql Connector - mysql

I have set up a grails app using grails 3.0.9
Now I want to add the mysql connector to bring up an connection to a mysql database.
Therefore I have added an entry to my build.gradle, but the connector is not fetched by 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
}
Don't know what I am doing wrong but I get an ClassNotFoundException.

Add runtime "mysql:mysql-connector-java:5.1.37" to your dependencies (Right under runtime "org.grails.plugins:asset-pipeline"). Then compile it. That should do the trick.
In my Grails 3 project I don't have a classpath to the connector, so I think it is save to remove it there.
Also don't forget to add these lines to your application.yml under your dataSource:
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect

Adding a local gradle installation to Intellij seems to solve the problem. I think that the included gradle-wrapper caused the trouble.
So downloading gradle 2.8 and setting it to use in Settings -> Build... -> Build Tools -> Gradle solved the problem.
Now the mysql connector is showing up under External Libraries
Gradle: mysql:mysql-connector-java:5.1.37

Related

I have been trying to upgrade grails to 4.0.7 but I get an error when running the application

The upgrade is from 3.3.10 to 4.0.7 I have followed the upgrade notes but as far as I understand spring has an issue with this plugin "org.grails.plugins.views-json" . I used a lot of json in the project so cannot just remove the plugin.
This is the error i am getting when the application run fails.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonSmartViewResolver': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.plugin.json.view.mvc.JsonViewResolver]: Constructor threw exception; nested exception is java.lang.AbstractMethodError
Please let me know if you have any ideas.
Thanks
Here's the build.gradle
buildscript {
repositories {
mavenLocal()
maven { url "http://artifactory.xxxxxx.xxxx.xxxx.xx/xxx/xx" }
maven { url "https://repo.xxxxx.xxxx/xxxxxx" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion" //4.0.7
classpath "gradle.plugin.com.energizedwork:idea-gradle-plugins:1.4"
classpath "org.grails.plugins:hibernate5:${gormVersion - ".RELEASE"}" //7.0.2
classpath "org.grails.plugins:views-gradle:2.1.0.M1"
classpath "net.saliman:gradle-cobertura-plugin:2.6.1"
}
}
version "1.1.2-" + System.getenv("CI_PIPELINE_ID") // Sprint 18
group "xxxxxxx"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: 'org.grails.grails-gsp'
apply plugin: "org.grails.grails-doc"
apply plugin: "org.grails.plugins.views-json"
apply plugin: 'codenarc'
apply plugin: "net.saliman.cobertura"
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
repositories {
mavenLocal()
maven { url "http://artifactory.xxxxxx.xxxx.xxxx.xx/xxx/xx" }
maven { url "https://repo.xxxxx.xxxx/xxxxxx" }
}
configurations {
all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
def VERSION = 'xxxxx-xxxxxx-2.0.0-xxxxxxxxx'
developmentOnly("org.springframework.boot:spring-boot-devtools")
//XXXXXX dependencies
compile group: 'xxx.xxxxx.xxx.xxxxxx', name: 'xxxxxx-xxx-api', version: VERSION, changing: true
compile group: 'xxx.xxxxx.xxx.xxxxxx', name: 'xxxxxx-xxxxxx', version: VERSION, changing: true
compile group: 'xxx.xxxxx.xxx.xxxxxx', name: 'xxxxxx-xxxxxx', version: VERSION, changing: true
compile 'xxx.xxxx.xxx.xxxxxx.xxxxxxxx:xxxxxxxxxxx-client:1.4.0'
compile 'xxx.xxxxx.xxx.xxxxx.plugins3:xxxxxx-xxxxx:2.1.0'
compile 'xxx.xxxxxx.xxxx.xxxxx.xxxx:xxx-rest-client:1.3.0'
//Additional dependencies
compile 'org.grails.plugins:spring-security-core:4.0.3'
compile 'org.grails.plugins:spring-security-rest:3.0.1'
compile 'org.grails.plugins:mail:3.0.0'
compile 'org.grails.plugins:gsp:4.1.0.M3'
compile 'org.awaitility:awaitility:3.1.6'
compile 'org.postgresql:postgresql:42.2.6'
compile 'software.amazon.awssdk:sns:2.7.31'
// Jobs
compile 'org.quartz-scheduler:quartz:latest.release'
compile 'org.grails.plugins:quartz:latest.release'
// initial dependencies
compile "org.grails:grails-datastore-gorm-rest-client:6.0.0.M1"
compile "org.grails:grails-web-common"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-codecs"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-datasource"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-ehcache"
compile "org.hibernate:hibernate-core:5.4.0.Final"
compile "org.grails.plugins:views-json:2.1.0.M1"
//compile "org.grails.plugins:views-json-templates"
compile "org.codehaus.groovy.modules.http-builder:http-builder:0.7"
console "org.grails:grails-console"
//compile "org.grails:grails-datastore-rest-client-6.1.12.RELEASE"
profile "org.grails.profiles:rest-api"
profile 'org.grails.profiles:web'
runtime "org.glassfish.web:el-impl:2.1.2-b05"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
//runtime "org.grails.plugins:views-json:2.0.2"
//runtime "org.springframework.boot:spring-boot-properties-migrator"
testCompile "org.grails.plugins:geb"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails:grails-web-testing-support"
compile 'cglib:cglib-nodep:3.2.12'
compile 'org.codehaus.jackson:jackson-core-asl:1.8.3'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.8.3'
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
sourceResources sourceSets.main
}
war {
archiveName 'xxxxxxx.war'
}
codenarc {
toolVersion = "1.4"
}
codenarcMain {
configFile = file( 'config/codenarc/codenarcMain.groovy' )
}
codenarcTest {
configFile = file( 'config/codenarc/codenarcTest.groovy' )
}
task codenarcAll {
group = 'other'
description = 'Runs all the codenarc checks'
dependsOn(codenarcTest, codenarcMain)
}
cobertura {
coverageFormats = ['html']
coverageIgnoreTrivial = true
}
// TODO not sure what to do about this. Needs to be 'true' for running locally. Needs to be false for building war.
// TODO Could create a new build-war target which turns it off.
grails.pathingJar = true
There is an incompatibility between 'org.grails.plugins:spring-security-core:4.0.3' and 'org.grails.plugins:spring-security-rest:3.0.1'
Better use older versions :‘org.grails.plugins:spring-security-core:3.2.0’ and ‘org.grails.plugins:spring-security-rest:2.0.0.M2’ -that means that you may review your grails version - while the issue being resolved.

Springboot version upgrade - my sql error while deploying in aws elastic beanstalk

We are trying to upgrade our project through build.gradle dependencies :
build.gradle file:
buildscript {
ext {
springBootVersion = '2.3.3.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
group = 'testing'
version = '0.0.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "jacoco"
apply from: 'docker.gradle'
sourceCompatibility = 1.8
bootJar {
launchScript()
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
compile ('org.springframework.boot:spring-boot-starter-data-jpa')
compile ('org.springframework.boot:spring-boot-starter-web')
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.flywaydb:flyway-core'
runtime 'mysql:mysql-connector-java:5.1.47'
implementation 'com.zaxxer:HikariCP'
annotationProcessor('org.hibernate:hibernate-jpamodelgen')
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.mobile:spring-mobile-device:1.1.5.RELEASE'
implementation 'io.jsonwebtoken:jjwt-api:0.10.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.10.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.10.5'
implementation 'com.amazonaws:aws-java-sdk-s3:1.11.136'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testCompile('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation('org.springframework.security:spring-security-test')
compile 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.apache.commons:commons-lang3'
implementation 'com.univocity:univocity-parsers:2.7.6'
implementation 'org.quartz-scheduler:quartz:2.2.1'
implementation 'org.apache.poi:poi:3.17'
implementation 'org.apache.poi:poi-ooxml:3.17'
}
test.reports.junitXml.setDestination(file("${buildDir}/test-results"))
jacocoTestReport {
reports {
html.destination file("${buildDir}/jacocoHtml")
}
}
sourceSets {
main {
java {
srcDirs += "src/jpaModelgen/java"
}
}
}
compileJava {
options.compilerArgs += ['-AaddGenerationDate=true'] // Specific to Hibernate JPA meta model generation processor.
options.annotationProcessorGeneratedSourcesDirectory = file("src/jpaModelgen/java")
}
application.properties file:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database=mysql
spring.data.jpa.repositories.enabled=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.url= jdbc:mysql://MyDB:3306/myschema
spring.datasource.username= testing
spring.datasource.password= root
spring-boot from version 1.5.7 to 2.3.3
Gradle from versionGradle-4.8-all to Gradle-6.4.1-all
while we run aplication in localy we get folowing output in log,
o.f.c.internal.database.DatabaseFactory : Database: jdbc:mysql://MyDB:3306/myschema (MySQL 5.7)
when we deploy this same code to AWS Elastic Beanstalk,
We are getting the following error:
Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException:
Migration V3__Sequence_Table.sql failed
---------------------------------------
SQL State : 42001
Error Code : 42001
Message : Syntax error in SQL statement "DELIMITER[*]
JDBC connection URL has been changed as below now,
o.f.c.internal.database.DatabaseFactory : Database: jdbc:h2:mem:testdb (H2 1.4)
Is this the cause of the above flyway migration error or Docker version error?
problem:
Run command for jar file is a problem for this project `
Dspring.config.location=run.properties this commad execute only run.properties
solution:
Instead of the above run command, I have tried this run command for the jar file
Dspring.config.additional-location=run.properties
this was working well

Gradle setup for OCI Java SDK in Intellij

I'm trying to setup Gradle for OCI Java SDK using implementation 'com.oracle.oci.sdk:oci-java-sdk-bom:1.8.0' provided in https://search.maven.org/artifact/com.oracle.oci.sdk/oci-java-sdk-bom/1.8.0/pom and getting Plugin not found error.
How can I setup Gradle properly for OCI
Below is my build.gradle
plugins {
id 'java'
id 'com.oracle.oci.sdk' version '1.8.0'
}
group 'mysample'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'com.oracle.oci.sdk:oci-java-sdk-bom:1.8.0'
}
You can use Spring's Dependency Management Plugin (https://docs.spring.io/dependency-management-plugin/docs/current-SNAPSHOT/reference/html/).
Example:
plugins {
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
dependencyManagement {
imports {
mavenBom 'com.oracle.oci.sdk:oci-java-sdk-bom:1.13.2'
}
}
dependencies {
implementation 'com.oracle.oci.sdk:oci-java-sdk-limits'
}
Please see the OCI gradle plugin at https://github.com/aalmiray/oci-gradle-plugin

Hibernate giving a NullPointerException when starting my Grails 3.1.0 Project [duplicate]

How do I make Grails 3.1.1 user Hibernate 5?
The following actions report Hibernate version 4.3.11.Final:
In Grails 3.1.1
grails create-app hello311
edit BootStrap.groovy as shown below
grails run-app
Console shows:
Hibernate version is: 4.3.11.Final
class BootStrap {
def init = { servletContext ->
println "Hibernate version is: ${org.hibernate.Version.getVersionString()}"
}
def destroy = {}
}
My build.gradle is unedited. The create-app command resulted in the following build.gradle file:
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:hibernate4:5.0.0"
}
}
version "0.1"
group "hello311"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.grails-gsp"
apply plugin:"asset-pipeline"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
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-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
console "org.grails:grails-console"
profile "org.grails.profiles:web:3.1.1"
runtime "org.grails.plugins:asset-pipeline"
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
Changing the hibernate4 dependency to hibernate5 does not work.
In build.gradle change the classpath dependency for the hibernate4 plugin at the top of the file in the buildscript{ dependencies {... section as follows:
classpath "org.grails.plugins:hibernate5:5.0.1"
The classpath section is there for the Gradle scrips like schemaExport, and that section does not support auto versioning.
Change the compile hibernate4 plugin dependency to the following:
compile "org.grails.plugins:hibernate5"
Add the following hibernate-core dependency:
compile "org.hibernate:hibernate-core:5.0.7.Final"
Change the hibernate-ehcache dependency to the 5.0.7.Final version.
compile "org.hibernate:hibernate-ehcache:5.0.7.Final"
In response to Ectoras comment on Burt's answer. Here is my full build.gradle file that works for me with Hibernate 5.
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:hibernate5:5.0.1"
classpath "org.grails.plugins:views-gradle:1.0.1"
}
}
version "0.1"
group "myGroup"
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"
apply plugin: "org.grails.plugins.views-json"
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:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:views-json:1.0.1"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.0.7.Final"
compile "org.hibernate:hibernate-ehcache:5.0.7.Final"
console "org.grails:grails-console"
profile "org.grails.profiles:web:3.1.1"
runtime "org.grails.plugins:asset-pipeline"
runtime files('grails-app/lib/ojdbc7.jar', 'grails-app/lib/xdb6.jar')
compile files('grails/src/java')
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
}

Specifying Gradle dependencies for *.jar files

This must be straight forward but I fail to see where group: name: and version: come from for a particular jar file. For example from Gradle's documentation.
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
testCompile group: 'junit', name: 'junit', version: '4.+'
testRuntime "org.hamcrest:SelfDescribing:1.+"
}
I'm trying to make use of a hamcrest jar for my junit testing. I need hamcrest for runtime testing but I don't know how to correctly specify this. Below is my build.gradle file. This test project will build successfully but will not run the unit tests due to unresolved dependencies.
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
version = '1.0'
compileJava.destinationDir = file("$buildDir/classes/test")
sourceSets {
main {
java {
srcDir 'src'
}
}
}
repositories {
flatDir dirs: "C:/eclipse/plugins/org.junit_4.11.0.v201303080030"
flatDir dirs: "C:/eclipse/plugins"
}
dependencies {
compile "junit:junit:4"
testCompile "junit:junit:4"
testRuntime "org.hamcrest:SelfDescribing:1.+"
}
test {
testLogging.showStandardStreams = true
testLogging {
events 'started', 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
exceptionFormat 'short'
}
}
jar {
manifest.attributes provider: 'gradle'
}
To add a dependency on a jar file, add a statement like this to your dependencies block:
compile files('path/to/archive.jar')
A popular approach is this, which will automatically pick up all jar files in a libs directory:
compile fileTree(dir: 'path/to/libs', include: '*.jar')
When using a flatDir repository, you'll have to make sure that:
Artifact files are contained directly in the specified directory (not in a subdirectory).
Artifact filenames match the pattern module-version.extension (e.g. junit-4.jar) or module.extension (e.g. junit.jar).
Alternatively, you could use file dependencies as described in Scott's answer.
PS: I'm not sure if version ranges work with flatDir repositories.