How to import a proprietary library in Grails 4.0.3 - grails

I am trying to import a proprietary jar lib (ICOMConector.jar) in my grails 4.0.3 project, but it is sending me an error.
In IntelliJ, I right-clicked the project folder and accessed Open Module Settings. Then I clicked in Libraries and chose my jar. Right after, clicked in Module / Dependencies and chose that jar in a compilation scope.
In build.gradle file I put this flatDir, because the jar in my project grails stardard structure:
repositories {
maven { url "https://repo.grails.org/grails/core" }
flatDir {
dirs 'lib'
}
}
And this in the same build.gradle, I've tried all of that, including those now commented,
but the error persists.
dependencies {
//implementation name: 'lib/ICOMConector.jar'
//runtime files('lib/ICOMConector.jar')
//runtime fileTree(dir: 'lib', include: '*.jar')
compile fileTree(dir: 'lib', include: ['*.jar'])
}
when I send grails run-app in the command line, the error is:
| Running application...
startup failed:
/media/alfredo/1TBHDD/CMB/Code projects/Grails 4/detran-mspid/grails-app/init/detran/mspid/BootStrap.groovy: 5: unable to resolve class com.workers.icom.ICOMConector
**# line 5, column 1.
import com.workers.icom.ICOMConector
^
1 error**
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
I tried to instantiate the class in Bootstrap.groovy, to make it easier to verify if it is working as expected.
Could anyone help me to import this library. A friend of mine did this in a Spring boot project and it worked, so the problem seems to be a wrong configuration in Grails.
package detran.mspid
import com.workers.icom.ICOMConector
class BootStrap {
def init = { servletContext ->
ICOMConector icom = new ICOMConector()
}
def destroy = {
}
}

This is what I have in my build.gradle for using a library in grails 4.0.3 (been this way since at least grails 3, though). This is almost identical to one you tried with runtime scope.
compile files("lib/opencsv-2.3.jar")
runtimeOnly fileTree(dir: './lib', include: ['*.jar'])
It's entirely possible that either one or both of those is unnecessary...

Related

Quartz not working in Grails4, Issue in dependency not able to compile

Getting error in Scheduler Dependency i'm using grails4 :
Anyone let me know correct dependency for scheduler
dependencies {
compile "org.grails.plugins:quartz:2.0.1"
}
and also tried this:
dependencies {
compile "com.agileorbit:schwartz:1.0.1"
}
Both are not able to compile:
grails run-app
| Resolving Dependencies. Please wait...
| Running application...
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':compileGroovy'.
org/quartz/JobExecutionContext
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 10s
| Error Failed to start server (Use --stacktrace to see the full trace)
You will need to add the quartz dependency explicitly in addition to the plugin as Gradle 5 stopped pulling in transitive dependancies. Also I'd suggest using the latest version (2.0.13 vs 2.0.1 which is quite old)
buildscript {
dependencies {
classpath 'org.grails.plugins:quartz:2.0.13' // Needed to compile *Job classes
}
}
dependencies {
compile 'org.grails.plugins:quartz:2.0.13'
compile 'org.quartz-scheduler:quartz:2.2.1' // Is not pulled in by default
}
We're using quartz in grails4 applications with:
dependencies {
//...
compile("org.quartz-scheduler:quartz:2.2.3") {
exclude group: 'slf4j-api', module: 'c3p0'
}
compile ('org.grails.plugins:quartz:2.0.13')
}
here's the issue description on github: https://github.com/grails-plugins/grails-quartz/issues/107

Gradle cannot find plugin

I have the following in my build.gradle of my Grails 3 project.
dependencies {
...
compile "org.grails.plugins:spring-security-core:3.0.3"
// The following line was the true cause of my problem
compile("org.grails.plugins:spring-security-oauth-google:0.3.1")
...
}
Now when I run Gradle I get this error:
Error Error initializing classpath: Could not find spring-security-core.zip (org.grails.plugins:spring-security-core:3.0.3).
Searched in the following locations:
https://repo.grails.org/grails/core/org/grails/plugins/spring-security-core/3.0.3/spring-security-core-3.0.3.zip (Use --stacktrace to see the full trace)
If I go to the specified path I do see the plugin but just as reported there is no zip file.
What am I doing wrong here?
The root for this problem I found in a little bit different place than expected.
I am working on upgrading a Grails 2.5 project to Grails 3 and I had lead myself on a wrong track. I needed to include spring-security-oauth-google and when it did not work as expected I also included spring-security-core which then derailed me.
The cause of this problem is dependencies being loaded from dependencies I have in my own project. In order to avoid loading those dependencies - called transitive dependencies - the following has to be done:
plugins {
compile "org.grails.plugins:spring-security-core:3.0.3"
compile("org.grails.plugins:spring-security-oauth-google:0.3.1") {
exclude group: 'org.grails.plugins', module: 'spring-security-core'
}
}
This will load the spring-security-core 3.0.3 correctly ignoring the dependency from spring-security-oauth-google.

Grails 3 scaffolding issue

I'm trying to port my project from Grails 2.4 to 3.0. Nothing fancy: 12 Domains, 13 Controllers and a service.
Everything works fine, except when I try to include the Scaffolding plugin. I literally follow the manual here, but the syntax must be wrong. Adding the plugin line as specified:
plugins {
…
compile ":scaffolding:2.0.0"
…
}
leads to this:
BUILD FAILED
Total time: 1.559 secs
| Error Error initializing classpath: startup failed:
build file 'E:\GrailsIdeaProjects\HcaServer\build.gradle': 17: only id(String) method calls allowed in plugins {} script block
See http://gradle.org/docs/2.3/userguide/plugins.html#sec:plugins_block for information on the plugins {} block
# line 17, column 5.
compile ":scaffolding:2.0.0"
^
1 error
(Use --stacktrace to see the full trace)
Somebody knows the right syntax to include the Scaffolding plugin in Grails 3?
EDIT: Thanks to Casey for pointing me in the right direction: Scaffolding plugin is actually already included in default build.gradle. Anyway, i still get a webpage like this on every controller:
Error: Page Not Found (404)
Path: /*controllerName*/index
I've been using the same syntax as per the manual, declaring a static scaffold = true on each controller. Why do I get a 404 page then? I do have index.gsp, error.gsp and notFound.gsp in my views folder.
It looks like that documentation hasn't been updated for Grails 3.0 yet. Your build.gradle file should have a dependencies block, where you can specify the dependency:
dependencies {
// ...
runtime "org.grails.plugins:scaffolding"
}
You can also see this by creating a new app using Grails 3.0 and checking out the default build.gradle file.
After researching for a while, turns out dynamic scaffolding hasn't made it yet into Grails 3:
https://groups.google.com/forum/m/#!topic/grails-dev-discuss/6R2YaF96Uts
Try this, It works for me.
dependencies {
compile "org.grails.plugins:scaffolding"
}
I am using grails 3.09.

Error resolving class with excel-report plugin

I am trying to install excel-plugin but I got an error resolving class.
..\plugins\excel-export-0.2.1\src\groovy\pl\touk\excel\export\XlsxExporter.groovy: 3: unable to resolve class groovy.transform.TypeChecked
# line 3, column 1.
import groovy.transform.TypeChecked
^
as installations say I have this in my BuildConfig file.
inherits("global") {
excludes 'xercesImpl'
excludes 'xercesImpl', 'xml-apis'
}
plugins {
runtime (":excel-export:0.2.1")
}
Any ideas ? I dont know which library I need.
I am using Grails 2.1.5
I've run into the same problem.
If you just uncomment the annotation at the start of the AdditionalSheet.groovy and XlsxExporter.groovy (and the import), your project should compile.

Read jars from lib folder in grails

I want to parse an excel file using the Apache POI library to boot strap some data in development mode into my grails 2.0.1 application.
I've tried to use the Grails excel-import plugin but the plugin uninstalls automatically when I execute run-app.
Because of that I decided to got ahead without the plugin for now. First I have copied the next jars into the grails application lib folder
$ls -la lib
poi-3.7-20101029.jar
poi-ooxml-3.7-20101029.jar
poi-ooxml-schemas-3.7-20101029.jar
xmlbeans-2.3.0.jar
I've read that I should declare the dependency in grails-app/conf/BuildConfig.groovy. So, I added the next:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
compile ('org.apache.poi:poi:3.7', 'org.apache.poi:poi-ooxml:3.7')
// runtime 'mysql:mysql-connector-java:5.1.16'
}
However when I execute run-app the application is still not able to find the jars.
grails> run-app
| Compiling 76 source files
| Compiling 30 source files.
| Error Compilation error: startup failed:
UMEExcelImporter.groovy: 8: unable to resolve class org.apache.poi.xssf.usermodel.XSSFSheet
# line 8, column 1.
import org.apache.poi.xssf.usermodel.XSSFSheet
^
UMEExcelImporter.groovy: 7: unable to resolve class org.apache.poi.xssf.usermodel.XSSFWorkbook
# line 7, column 1.
import org.apache.poi.xssf.usermodel.XSSFWorkbook
^
UMEExcelImporter.groovy: 9: unable to resolve class org.apache.poi.xssf.usermodel.XSSFRow
# line 9, column 1.
import org.apache.poi.xssf.usermodel.XSSFRow
I am not using any IDE. Any feedback is welcome!
The POI jars are on public Maven repo's so try this:
Remove the jars from your lib folder
Clean your build with: grails clean
In you BuildConfig.groovy ensure that the "repositories" closure has "mavenCentral()" included/uncommented
Your dependency looks ok (I have not confirmed it) so now try the run-app
HTH
instead of adding compile dependency, try adding runtime dependency as follows.
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
runtime ('org.apache.poi:poi:3.7', 'org.apache.poi:poi-ooxml:3.7')
// runtime 'mysql:mysql-connector-java:5.1.16'
}

Resources