Getting unable to resolve class org.apache.commons.configuration.PropertiesConfiguration - grails

Iam new to groovy on grails.
In my grails application i have to edit a property file without deleting other key values for that Iam using apache commons following code
PropertiesConfiguration conf = new PropertiesConfiguration("config.properties");
props.setProperty("key", "value");
conf.save();
In BuildConfig.groovy I have included the depentencies
dependencies {
compile 'org.apache.commons:commons-configuration2:2.2'
compile 'org.apache.commons:commons-lang3:3.1'
}
While executing grails compile the dependencies seems to be downloaded without any error, but that Iam getting the compilation error
unable to resolve class org.apache.commons.configuration.PropertiesConfiguration
[groovyc] # line 5, column 1.
[groovyc] import org.apache.commons.configuration.PropertiesConfiguration;
[groovyc] ^
[groovyc]
What additional settings that i need to do in grails please suggest

Use
import org.apache.commons.configuration2.PropertiesConfiguration;
Note the 2 at the end of configuration!

Related

How to import a proprietary library in Grails 4.0.3

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...

Unable to compile groovy script in Jenkins

The script is working fine in groovy console. But when I do check-syntax for the same script in Jenkins, the following error message is coming up -
Script1.groovy: 6: unable to resolve class groovyx.net.http.RESTClient
# line 6, column 1.
import groovyx.net.http.RESTClient
^
Script1.groovy: 4: unable to resolve class groovyx.net.http.ContentType
# line 4, column 1.
import groovyx.net.http.ContentType
^
Script1.groovy: 3: unable to resolve class groovyx.net.http.HTTPBuilder
# line 3, column 1.
import groovyx.net.http.HTTPBuilder....
How to get this issue resolved?
This exception is because you dont have these dependencies (Jars) that has these classes so you have two option :
1- if you currently using any dependency management framework like (maven,gradle) then just add these dependencies
2- in the groovy file at the top add #Grapes and then add the dependency here an example :
#Grapes(
#Grab(group='yourDependencyGroupID', module='yourDependencyArtifactID'
, version='theDesireVersion')
)
you can search for these dependencies in Maven Repository
i hope this will help :)

Compile error with grails 2.4.1 and plugin joda-time 1.5

When compiling a grails 2.4.1 project I get the following error:
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] /home/omarques/ws1/sigob/target/work/plugins/joda-time-1.5/src/groovy/grails/plugin/jodatime/simpledatastore/SimpleMapJodaTimeMarshaller.groovy: 44: Apparent variable 'MonthDay' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
[groovyc] You attempted to reference a variable in the binding or an instance variable from a static context.
[groovyc] You misspelled a classname or statically imported field. Please check the spelling.
[groovyc] You attempted to use a method 'MonthDay' but left out brackets in a place not allowed by the grammar.
[groovyc] # line 44, column 87.
[groovyc] me, LocalDate, LocalDateTime, MonthDay,
[groovyc] ^
I've tried to upgrade the project to 2.4.3 and got the same error
Add the following to application.properties and try
plugins.joda-time=1.3.1
the problem was solved by including on BuildConfig an explicit dependency to joda-time-2.3 because another dependency(net.objectlab.kit:datecalc-joda:1.2.0) was causing the use of an outdated version of joda-time that is incompatible with the joda-time grails plugin

grails heroku plugin - unable to resolve class grails.plugin.cloudsupport.AbstractCloudTagLib

When I run the
git push heroku master
command, I get the following error (below). Per one this thread, I uninstalled the heroku plugin, installed the cloud-support plugin, and re-installed the heroku plugin. That didn't change the error. I entered a JIRA on this at the plugin, but am posting here so that there is an easy reference to whatever solution the grails folks are able to provide or in case dialogue on the problem/solution is required.
Thanks
Error is:
[mkdir] Created dir: /app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/tomcat-1.3.7
[unzip] Expanding: /app/tmp/repo.git/.cache/cache/org.grails.plugins/tomcat/zips/tomcat-1.3.7.zip into
/app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/tomcat-1.3.7
Installed plugin tomcat-1.3.7 to location /app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/tomcat-
1.3.7. ...
Executing tomcat-1.3.7 plugin post-install script ...
Plugin tomcat-1.3.7 installed
Plugin provides the following new scripts:
------------------------------------------
grails tomcat
[mkdir] Created dir: /app/.grails/1.3.7/projects/build_36v61myh1movb/plugin-classes
[groovyc] Compiling 106 source files to /app/.grails/1.3.7/projects/build_36v61myh1movb/plugin-classes
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] /app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/heroku-1.0/grails-
app/taglib/grails/plugin/heroku/HerokuTagLib.groovy: 17: unable to resolve class grails.plugin.cloudsupport.AbstractCloudTagLib
[groovyc] # line 17, column 1.
[groovyc] import grails.plugin.cloudsupport.AbstractCloudTagLib
[groovyc] ^
[groovyc]
[groovyc] /app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/heroku-1.0/grails-
app/taglib/grails/plugin/heroku/HerokuTagLib.groovy: 22: unable to resolve class grails.plugin.cloudsupport.Abstr
actCloudTagLib
[groovyc] # line 22, column 1.
[groovyc] class HerokuTagLib extends AbstractCloudTagLib {
[groovyc] ^
[groovyc]
[groovyc] /app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/heroku-
1.0/src/groovy/grails/plugin/heroku/HerokuBeanPostprocessor.groovy: 17: unable to resolve class
grails.plugin.cloudsupport.A
bstractCloudBeanPostprocessor
[groovyc] # line 17, column 1.
[groovyc] import grails.plugin.cloudsupport.AbstractCloudBeanPostprocessor
[groovyc] ^
[groovyc]
[groovyc] /app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/heroku-
1.0/src/groovy/grails/plugin/heroku/HerokuBeanPostprocessor.groovy: 27: unable to resolve class
grails.plugin.cloudsupport.A
bstractCloudBeanPostprocessor
[groovyc] # line 27, column 1.
[groovyc] class HerokuBeanPostprocessor extends AbstractCloudBeanPostprocessor {
[groovyc] ^
[groovyc]
[groovyc] /app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/heroku-
1.0/src/groovy/grails/plugin/heroku/HerokuMongoBeanConfigurer.groovy: 17: unable to resolve class
grails.plugin.cloudsupport
.AbstractMongoBeanConfigurer
[groovyc] # line 17, column 1.
[groovyc] import grails.plugin.cloudsupport.AbstractMongoBeanConfigurer
[groovyc] ^
[groovyc]
[groovyc] /app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/heroku-
1.0/src/groovy/grails/plugin/heroku/HerokuMongoBeanConfigurer.groovy: 24: unable to resolve class
grails.plugin.cloudsupport
.AbstractMongoBeanConfigurer
[groovyc] # line 24, column 1.
[groovyc] class HerokuMongoBeanConfigurer extends AbstractMongoBeanConfigurer {
[groovyc] ^
[groovyc]
[groovyc] 6 errors
Error executing script Compile: : Compilation Failed
: Compilation Failed
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:391)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: : Compilation Failed
at org.codehaus.groovy.ant.Groovyc.compile(Groovyc.java:920)
at org.codehaus.groovy.ant.Groovyc.execute(Groovyc.java:607)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at Compile$_run_closure4_closure10.doCall(Compile:117)
at Compile$_run_closure4_closure10.doCall(Compile)
at Compile$_run_closure10.doCall(Compile:280)
at Compile$_run_closure10.call(Compile)
at Compile$_run_closure4.doCall(Compile:104)
at Compile$_run_closure3.doCall(Compile:69)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
... 10 more
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/app/.grails/1.3.7/projects/build_36v61myh1movb/plugins/heroku-1.0/grails-
app/taglib/grails/plugin/heroku/HerokuTagLib.groovy: 17: unable to resolve class
grails.plugin.cloudsupport.AbstractCloudTagLib
Problems before this, note git push gives me no opportunity to respond to the [y,n] prompts:
Plugin mail-1.0 installed
Resolving plugin JAR dependencies ...
Executing spring-security-ui-0.1.2 plugin post-install script ...
Plugin spring-security-ui-0.1.2 installed
Plugin provides the following new scripts:
------------------------------------------
grails s2ui-override
You currently already have a version of the plugin installed [mail-1.0]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
You currently already have a version of the plugin installed [mail-1.0]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
You currently already have a version of the plugin installed [mail-1.0]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
No valid response entered - giving up asking.
Plugin mail-1.0-SNAPSHOT install aborted ...
You currently already have a version of the plugin installed [spring-security-core-1.2.7.1]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
You currently already have a version of the plugin installed [spring-security-core-1.2.7.1]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
You currently already have a version of the plugin installed [spring-security-core-1.2.7.1]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
No valid response entered - giving up asking.
Plugin spring-security-core-1.2.1 install aborted ...
You currently already have a version of the plugin installed [jquery-1.7.1]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
You currently already have a version of the plugin installed [jquery-1.7.1]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
You currently already have a version of the plugin installed [jquery-1.7.1]. Do you want to upgrade this version? [y,n]
Invalid option 'null' - must be one of: [y,n]
No valid response entered - giving up asking.
Plugin jquery-1.6.1.1 install aborted ...
[mkdir] Created dir: /app/.grails/1.3.7/projects/build_28p9jo3vo48wb/plugin-classes
[groovyc] Compiling 106 source files to /app/.grails/1.3.7/projects/build_28p9jo3vo48wb/plugin-classes
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] /app/.grails/1.3.7/projects/build_28p9jo3vo48wb/plugins/heroku-1.0/grails-app/taglib/grails/plugin/heroku/HerokuTagLib.groovy: 17: unable to resolve class grails.plugin.cloudsupport.Abstr
actCloudTagLib
[groovyc] # line 17, column 1.
[groovyc] import grails.plugin.cloudsupport.AbstractCloudTagLib
[groovyc] ^
[groovyc]
I too had this problem with grails 1.3.7.
As suggested by Burt, adding the following to your BuildConfig.groovy will resolve the problem:
compile ':cloud-support:1.0.8'
I've followed the Basic Tutorial of Burt's here, after the above was added, my web-app compiled and deployed to Heroku successfully.
Installing the cloud-support plugin is the fix. Try running grails clean and grails compile to get it to resolve the dependencies.

STS - Can't Find Grails Library

I am porting over Grails project to STS and I don't know much about the project nor about STS, so I am a little lost. Also of note is that the project was previously in Grails 1.0.3 and I am upgrading it to 1.3.7.
After loading in the existing code, I configured my project to use Grails 1.3.7. When I attempt to build the project I get a bunch of errors relating to what appears to be just basic grails code that should come with 1.3.7:
e.g. Groovy:unable to resolve class org.codehaus.groovy.grails.commons.ConfigurationHolder
Also, when I open STS I am asked to run an "upgrade" for grails, which fails with the following:
Command terminated with an error code (see details for output)
------System.out:-----------
Welcome to Grails 1.3.7 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /home/devon/springsource/grails-1.3.7/
Base Directory: /home/devon/Documents/Source/trunk
Resolving dependencies...
Dependencies resolved in 2458ms.
Running script /home/devon/springsource/grails-1.3.7/scripts/Compile.groovy
Environment set to development
Setting non-interactive mode
[groovyc] Compiling 110 source files to /home/devon/.grails/1.3.7/projects/trunk/classes
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] Compile error during compilation with javac.
[groovyc] /tmp/groovy-generated-1742177078522700179-java-source/com/pps/domain/User.java:62: package org.grails.plugins.springsecurity.service does not exist
[groovyc] public org.grails.plugins.springsecurity.service.AuthenticateService getAuthenticateService() { return (org.grails.plugins.springsecurity.service.AuthenticateService)null;}
[groovyc] ^
[groovyc] /tmp/groovy-generated-1742177078522700179-java-source/com/pps/domain/User.java:63: package org.grails.plugins.springsecurity.service does not exist
[groovyc] public void setAuthenticateService(org.grails.plugins.springsecurity.service.AuthenticateService value) { }
[groovyc] ^
[groovyc] /home/devon/Documents/Source/trunk/src/java/com/pps/util/MarketplaceWidgetUtils.java:24: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
[groovyc] import sun.misc.BASE64Encoder;
[groovyc] ^
[groovyc] /tmp/groovy-generated-1742177078522700179-java-source/com/pps/domain/User.java:62: package org.grails.plugins.springsecurity.service does not exist
[groovyc] public org.grails.plugins.springsecurity.service.AuthenticateService getAuthenticateService() { return (org.grails.plugins.springsecurity.service.AuthenticateService)null;}
[groovyc] ^
[groovyc] /home/devon/Documents/Source/trunk/src/java/com/pps/util/MarketplaceWidgetUtils.java:170: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
[groovyc] BASE64Encoder encoder = new BASE64Encoder();
[groovyc] ^
[groovyc] /home/devon/Documents/Source/trunk/src/java/com/pps/util/MarketplaceWidgetUtils.java:170: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
[groovyc] BASE64Encoder encoder = new BASE64Encoder();
[groovyc] ^
[groovyc] 3 errors
[groovyc] 3 warnings
[groovyc]
[groovyc]
[groovyc] 1 error
Compilation error: Compilation Failed
------System.err:-----------
In my Java Build Path I have a 'Grails Dependencies' folder, but I don't know how to change it to make sure it is pointing to the right dependencies. There is also 'Groovy Libraries' and a bunch of random '.jar' dependencies.
What am I doing wrong?
It looks like it wasn't finding it because required dependencies to plugins were not resolving correctly. Once I got the plugins it worked correctly.

Resources