Specifying Gradle dependencies for *.jar files - junit

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.

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.

How do I configure jooq with Gradle and Mysql for a single database

I'm trying to use jooq to load configurations automatically from gradle but had a hard time following the guide.
I finally have it loading data, but so far I can only get all databases to work (by having the database() chunk be blank).
My code below has my attempt to load only one database.
buildscript {
repositories {
mavenCentral()
maven {
name 'JFrog OSS snapshot repo'
url 'https://oss.jfrog.org/oss-snapshot-local/'
}
jcenter()
}
dependencies {
classpath 'org.jooq:jooq-codegen:3.9.1'
classpath group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
}
}
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'antlr'
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
//compile group: 'com.github.javaparser', name: 'javaparser-core', version: '3.0.0-alpha.2'
compile group: 'com.github.javaparser', name: 'java-symbol-solver-core', version: '0.5.2'
compile 'org.jooq:jooq:3.9.1'
runtime group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
testCompile "junit:junit:latest.release"
}
idea {
module {
excludeDirs += file('src/main/resources')
}
}
// Use your favourite XML builder to construct the code generation configuration file
// ----------------------------------------------------------------------------------
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.9.0.xsd') {
jdbc() {
driver('com.mysql.cj.jdbc.Driver')
url('jdbc:mysql://127.0.0.1/graphUpgrade?serverTimezone=UTC')
user('parseUser')
password('password')
}
generator() {
database() {
name('org.jooq.util.mysql.MySQLDatabase')
inputSchema('graphUpgrade')
includes('.*')
}
// Watch out for this caveat when using MarkupBuilder with "reserved names"
// - https://github.com/jOOQ/jOOQ/issues/4797
// - http://stackoverflow.com/a/11389034/521799
// - https://groups.google.com/forum/#!topic/jooq-user/wi4S9rRxk4A
generate([:]) {
pojos true
daos true
}
target() {
packageName('us.klingman.codeParser.db')
directory('src/main/java')
}
}
}
print writer.toString()
// Run the code generator
// ----------------------
org.jooq.util.GenerationTool.generate(
javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)
Running this code produces the following error:
Error while fetching tables
java.lang.NullPointerException
at org.jooq.util.AbstractElementContainerDefinition.<init>(AbstractElementContainerDefinition.java:79)
at org.jooq.util.AbstractElementContainerDefinition.<init>(AbstractElementContainerDefinition.java:75)
at org.jooq.util.AbstractTableDefinition.<init>(AbstractTableDefinition.java:68)
at org.jooq.util.mysql.MySQLTableDefinition.<init>(MySQLTableDefinition.java:70)
at org.jooq.util.mysql.MySQLDatabase.getTables0(MySQLDatabase.java:256)
at org.jooq.util.AbstractDatabase.getTables(AbstractDatabase.java:1137)
at org.jooq.util.AbstractDatabase.getTable(AbstractDatabase.java:1163)
at org.jooq.util.AbstractDatabase.getTable(AbstractDatabase.java:1158)
at org.jooq.util.mysql.MySQLDatabase.getEnums0(MySQLDatabase.java:295)
at org.jooq.util.AbstractDatabase.getEnums(AbstractDatabase.java:1182)
at org.jooq.util.JavaGenerator.generateSchemaIfEmpty(JavaGenerator.java:334)
at org.jooq.util.JavaGenerator.generateCatalogIfEmpty(JavaGenerator.java:323)
at org.jooq.util.JavaGenerator.generate(JavaGenerator.java:297)
at org.jooq.util.GenerationTool.run(GenerationTool.java:610)
at org.jooq.util.GenerationTool.generate(GenerationTool.java:199)
at org.jooq.util.GenerationTool$generate.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at build_87hklhc6v691dvh83y5ogqnvl.run(/Users/lorenklingman/Sites/code-search-parser/build.gradle:79)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:74)
Finally, for completeness, here are the files generated for all databases.
I believe you've run into this problem here: #5213
Be sure to always use the exact upper/lower case writing of your database name also in the jOOQ configuration. Also, there are some caveats with case sensitivity in MySQL and MariaDB, depending on the operating system. These caveats can affect other tools than jOOQ. The relevant info is also in #5213.

Using mongodb and hibernate with grails3

I need to run a Grails 3 app against MySql/Hibernate and MongoDB.
(Had is running on Grails 2.5 without an hitch).
I tried many different combinations, searched and tried related SO answers, but with no luck.
Used the latest Mongodb plugin doc for the configuration.
Using Grails 3.1.10:
grailsVersion=3.1.10
I started with the following details in build.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.8.2"
classpath "org.grails.plugins:hibernate4:5.0.10"
}
}
...
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"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
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"
//databases
compile 'org.grails.plugins:mongodb:6.0.0.M2'
runtime 'mysql:mysql-connector-java:5.1.36'
...
}
The application.yml:
---
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
environments:
development:
dataSource:
dbCreate: update
url: jdbc:mysql://localhost:3306/dbname
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username : "xxx"
password : "yyy"
properties:
maxActive : 50
maxIdle: 25
minIdle: 5
...
grails:
mongodb:
host: "localhost"
port: 27017
username: "blah"
password: "blah"
databaseName: "foo"
Now this gives me an error:
15:13:58.001 [QUIET] [system.out] ERROR org.springframework.boot.SpringApplication - Application startup failed
15:13:58.001 [QUIET] [system.out] java.lang.NoClassDefFoundError: org/grails/datastore/gorm/plugin/support/ConfigSupport
15:13:58.001 [QUIET] [system.out] at grails.plugins.mongodb.MongodbGrailsPlugin.doWithSpring(MongodbGrailsPlugin.groovy:42)
The MongoDB grails plugin does not find ConfigSupport
ConfigSupport.prepareConfig(config, (ConfigurableApplicationContext) applicationContext)
I then tried to add the following plugins in all orders possible:
//compile 'org.grails:grails-datastore-gorm-hibernate4:6.0.0.M2'
//compile 'org.grails:grails-datastore-core:4.0.0.M2'
//compile 'org.grails:grails-datastore-gorm-plugin-support:6.0.0.M2'
//compile 'org.springframework.data:spring-data-mongodb:1.9.2.RELEASE'
//compile 'org.mongodb:mongodb-driver:3.3.0'
//compile 'org.mongodb:mongo-java-driver:3.3.0'
No luck.
I also moved the mongodb: section down to the grails: section in the yml file. Same error.
So the question is how to get MongoDB running with MySql with grails3.
Ok, stupid me. I solved the puzzle using these simple dependency settings:
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"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
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"
//databases
compile 'org.grails.plugins:mongodb'
runtime 'mysql:mysql-connector-java:5.1.36'
runtime 'com.googlecode.json-simple:json-simple:1.1'
It seems that the following line made the difference:
compile 'org.grails.plugins:mongodb'
Omitting the version number. This should be explained in the docs a bit better. Usually it is a good thing defining versions, or is this too old fashioned these days? :-)
Happy to have it working
Ok I found correct previous answer for referring mongodb plugin, i.e. compile 'org.grails.plugins:mongodb' but I want to sum up with a brief checklist, having me a correctly running mixed solution (both hibernate + mysql and mongodb), after many trials and errors. So, in order to have a mixed mysql/mongo grails3 configuration, you have to
insert compile 'org.grails.plugins:mongodb' (without any version) in build.gradle (remember that there is no BuildConfig.groovy in grails 3, as documented here/grails2->3)
keep ordinary dependency to hibernate/mysql, for example: compile 'org.grails.plugins:hibernate4' compile 'org.hibernate:hibernate-ehcache' runtime 'mysql:mysql-connector-java:5.1.38'
set up correctly connections in application.yml, but I prefer old-style application.groovy, in grails-app/conf (as in older GRAILS), as below (remember that in GRAILS3 differently from 2 you have to use mongodb and no more mongo keyword)
use ordinary GRAILS entities for mysql mapping
and use static mapWith="mongo" inside mongo entities (as stated in GRAILS-mongo doc)
not use usual mysql Long id for mongo, but ObjectId id, and for it import org.bson.types.ObjectId
Application.groovy set up
grails {
mongodb {
host = "localhost"
port = 27017
username = mongouser
password= mongopasswd
databaseName = mongoDBname
}
}
environments {
development {
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
username = ...
password = ...
dbCreate = "create"
url = "jdbc:mysql://127.0.0.1:3306/dbnameMysql"
}
}
}
That's all. Enjoy MongoDB.
Not sure I can help much other than show my config that is confirmed working.
I've recently converted a 2.4.4 app to 3.1.8, admittedly I'm using Oracle as my RDBMS rather than mysql.
In build.gradle I just have:
dependencies {
classpath "org.grails.plugins:hibernate4:5.0.6"
...
}
dependencies {
compile "org.grails.plugins:mongodb:5.0.0.RC1"
...
}
And in application.yml:
mongodb:
databaseName: 'myApp'
engine: mapping
The engine: mapping bit was crucial for me, it reverts to the previous persistence engine as described here http://gorm.grails.org/latest/mongodb/manual/index.html
The doWithSpring() closure in my MongodbGrailsPlugin.groovy looks like:
Closure doWithSpring() {
def initializer = new MongoDbDataStoreSpringInitializer(config, grailsApplication.getArtefacts(DomainClassArtefactHandler.TYPE).collect() { GrailsClass cls -> cls.clazz })
initializer.registerApplicationIfNotPresent = false
initializer.setSecondaryDatastore( manager.hasGrailsPlugin("hibernate") )
return initializer.getBeanDefinitions((BeanDefinitionRegistry)applicationContext)
}
No reference to ConfigSupport which may have been added (or not) in your later version or there's a dependency missing.

Grails 3 - Gradle dependecies Mysql Connector

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

I'm getting java.lang.UnsatisfiedLinkError when I run my jUnit test on command line by gradle, but it runs fine when run on AndroidStudio

So I finally managed to get my android studio to run JUnit test that's integrated with robolectric so I can do http calls and other things without running it on device or emulator. Followed the structure from here which worked wonders: https://github.com/robolectric/deckard-gradle
Now, I managed to run it fine on AndroidStudio, however I want to setup a cron so it can be run automatically, and when executing the test by command line via gradle I am getting "java.lang.UnsatisfiedLinkError: no pjsua in java.library.path". Note that our code uses a pjsip lib code that we compile separately, and we put the .so file in the jniLibs folder. I have another jUnit test that's really simple, and that one works fine whether through gradle command line or AndroidStudio.
The gradle command I followed from http://tools.android.com/tech-docs/unit-testing-support which are either:
1) ./gradlew test --continue
or
2) ./gradlew test -Dtest.single=Test.java
This is what our gradle file looks like for the app layer:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.foo.test"
minSdkVersion 14
targetSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
moduleName "libpjsua"
}
}
sourceSets {
main {
jni.srcDirs = []
}
}
signingConfigs {
// hidden
}
buildTypes {
release {
signingConfig signingConfigs.release
}
debug {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/android-logging-log4j-1.0.3.jar')
compile files('libs/libphonenumber-6.2.jar')
compile files('libs/log4j-1.2.17.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/ostermillerutils_1_07_00.jar')
// dependencies to do automation testing
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile 'org.hamcrest:hamcrest-integration:1.1'
testCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
}
Does anyone have any idea? Many thanks in advance, been at this for a couple of days now.