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 :)
Related
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!
I need to use some classes in httpclient.jar when building a project in Jenkins. I added this jar to both {Groovy_Classpath}\lib and {Jenkins_Path}\plugins\groovy\WEB-INF\lib and tried to imported into my job (also see the screenshot below):
import jenkins.model.*
import hudson.model.*
import groovy.*
import org.apache.http.*
HttpClient httpClient = HttpClientBuilder.create().build();
It has two issues:
startup failed:
Script1.groovy: 6: unable to resolve class HttpClient
# line 6, column 12.
HttpClient httpClient = HttpClientBuilder.create().build();
^
1 error
So I removed HttpClient and saw another:
Caught: groovy.lang.MissingPropertyException: No such property: HttpClientBuilder for class: xxxx
groovy.lang.MissingPropertyException: No such property: HttpClientBuilder
I guess probably they meant the same thing - the class couldn't be found. But I have no idea how to resolve as I've added the jar to classpath...
Updated on the basis of Mike W's suggesion
Try getting the dependency using Grape, add the following to the top of your script.
#Grab(group='org.apache.httpcomponents', module='httpclient', version='4.5.3'))
I'm in process of upgrading an app from Grails v2 to v3 .
I got to a point where it works reasonably well with Grails 3.0.17.
I wanted to upgrade it to v3.1 or v3.2. But after changing the version in gradle.properties that's what I get after executing grails run-app:
me#host:[~/](feature/grails3-migration) : grails run-app
| Error Error occurred running Grails CLI: startup failed:
script14867378818131525390840.groovy: 3: unable to resolve class xxx.yyy.CollectorsJob
# line 3, column 1.
import xxx.yyy.jobs.CollectorsJob
^
script14867378818131525390840.groovy: 6: unable to resolve class xxx.yyy.domain.business.Company
# line 6, column 1.
import xxx.yyy.domain.business.Company
^
script14867378818131525390840.groovy: 5: unable to resolve class xxx.yyy.domain.access.User
# line 5, column 1.
import xxx.yyy.domain.access.User
^
...
There's about 15 errors like that printed.
What's the problem here? I've tried clear the project and change the jdk version fro 1.8 -> 1.7. Each time the same result.
If you are referencing application classes in grails-app/conf/application.groovy these will need to be moved to your runtime configuration in grails-app/conf/runtime.groovy
The application.groovy file is parsed by the build system in addition to the runtime so cannot contain references to classes that are not yet compiled
I've got a plugin called Media which should take care of image resizing and so on.
It has these dependences:
dependencies {
compile group: 'org.ccil.cowan.tagsoup',
name: 'tagsoup',
version: '1.2'
runtime group: 'org.codehaus.groovy.modules.http-builder',
name: 'http-builder',
version: '0.5.2'
compile group: 'org.imgscalr',
name: 'imgscalr-lib',
version:'4.2'
compile group: 'org.apache.tika',
name: 'tika-core',
version: '1.3'
}
When I run plugin as a standalone application everything works fine.
Than I created an application and added inplace plugin dependency to my BuildConfig.groovy file.
// there is grails.project.dependency.resolution closure above
grails.plugin.location.Media = "../../plugins/Media";
When I run-app my application I get this error:
| Error Compilation error: startup failed:
/home/grails/plugins/Media/grails-app/controllers/frod/media/ImageServiceController.groovy: 14: unable to resolve class org.imgscalr.Scalr
# line 14, column 1.
import org.imgscalr.Scalr
^
/home/grails/plugins/Media/src/groovy/frod/media/download/CachedContentDownloader.groovy: 3: unable to resolve class org.apache.http.HttpResponse
# line 3, column 1.
import org.apache.http.HttpResponse
^
/home/grails/plugins/Media/src/groovy/frod/media/download/ContentDownloader.groovy: 3: unable to resolve class org.apache.http.HttpResponse
# line 3, column 1.
import org.apache.http.HttpResponse
^
/home/grails/plugins/Media/src/groovy/frod/media/download/ContentDownloader.groovy: 4: unable to resolve class org.apache.http.client.HttpClient
# line 4, column 1.
import org.apache.http.client.HttpClient
^
/home/grails/plugins/Media/src/groovy/frod/media/download/ContentDownloader.groovy: 6: unable to resolve class org.apache.http.impl.client.DefaultHttpClient
# line 6, column 1.
import org.apache.http.impl.client.DefaultHttpClient
^
/home/grails/plugins/Media/src/groovy/frod/media/download/ContentDownloader.groovy: 5: unable to resolve class org.apache.http.client.methods.HttpGet
# line 5, column 1.
import org.apache.http.client.methods.HttpGet
^
/home/grails/plugins/Media/src/groovy/frod/media/download/DownloadedContent.groovy: 3: unable to resolve class org.apache.http.HttpEntity
# line 3, column 1.
import org.apache.http.HttpEntity
^
/home/grails/plugins/Media/src/groovy/frod/media/download/IContentDownloader.groovy: 3: unable to resolve class org.apache.http.HttpResponse
# line 3, column 1.
import org.apache.http.HttpResponse
^
/home/grails/plugins/Media/src/groovy/frod/media/image/thumbnail/adjustment/crop/CropProcessor.groovy: 5: unable to resolve class org.imgscalr.Scalr
# line 5, column 1.
import org.imgscalr.Scalr
^
/home/grails/plugins/Media/src/groovy/frod/media/image/thumbnail/adjustment/resize/IResizeAdjustment.groovy: 3: unable to resolve class org.imgscalr.Scalr
# line 3, column 1.
import org.imgscalr.Scalr
^
/home/grails/plugins/Media/src/groovy/frod/media/image/thumbnail/adjustment/resize/IResizeAdjustment.groovy: 16: unable to resolve class Scalr.Mode
# line 16, column 5.
public Scalr.Mode getMode();
^
/home/grails/plugins/Media/src/groovy/frod/media/image/thumbnail/adjustment/resize/IResizeAdjustment.groovy: 18: unable to resolve class Scalr.Method
# line 18, column 5.
public Scalr.Method getMethod();
^
// and many others
As you can see it couldn't resolve dependencies (you can see http-builder imgscalr-lib).
I googled much and found I could try to set legacyResolve true. I tried all combinations (plugin, app, plugin + app) with these settings and with the same result - the error above.
Can anyone help me with this?
My grails version is 2.2.3
Thank you very much
Frank
Dependencies are resolved by Ivy, but this depends on POM files being available. This isn't the case when you use inline plugins since you're just pointing to the plugin source. You can either be redundant and add the dependencies to the app's BuildConfig, or use the maven-install script which packages the plugin and copies it to your local Maven cache.
maven-install is a bit less convenient since you have to re-run it every time you make a change in the plugin that you need to have available to the application, but it's closer to the real install process. To use a plugin that's been published locally like this, ensure that mavenLocal() is uncommented in BuildConfig.groovy and add a dependency like you would if you had released the plugin, e.g. compile ':myplugin:0.1'
Here are the logs from startup
| Compiling 342 source files.
| Error Compilation error: startup failed:
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 19: unable to resolve class org.tmatesoft.svn.core.wc.SVNStatus
# line 19, column 1.
import org.tmatesoft.svn.core.wc.SVNStatus
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 7: unable to resolve class org.tmatesoft.svn.core.SVNProperties
# line 7, column 1.
import org.tmatesoft.svn.core.SVNProperties
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 10: unable to resolve class org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory
# line 10, column 1.
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 16: unable to resolve class org.tmatesoft.svn.core.wc.SVNCopyClient
# line 16, column 1.
import org.tmatesoft.svn.core.wc.SVNCopyClient
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 17: unable to resolve class org.tmatesoft.svn.core.wc.SVNCopySource
# line 17, column 1.
import org.tmatesoft.svn.core.wc.SVNCopySource
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 4: unable to resolve class org.tmatesoft.svn.core.SVNDepth
# line 4, column 1.
import org.tmatesoft.svn.core.SVNDepth
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 5: unable to resolve class org.tmatesoft.svn.core.SVNException
# line 5, column 1.
import org.tmatesoft.svn.core.SVNException
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 20: unable to resolve class org.tmatesoft.svn.core.wc.SVNStatusClient
# line 20, column 1.
import org.tmatesoft.svn.core.wc.SVNStatusClient
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 12: unable to resolve class org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl
# line 12, column 1.
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 3: unable to resolve class org.tmatesoft.svn.core.SVNAuthenticationException
# line 3, column 1.
import org.tmatesoft.svn.core.SVNAuthenticationException
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 24: unable to resolve class org.tmatesoft.svn.core.wc.SVNWCUtil
# line 24, column 1.
import org.tmatesoft.svn.core.wc.SVNWCUtil
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 6: unable to resolve class org.tmatesoft.svn.core.SVNNodeKind
# line 6, column 1.
import org.tmatesoft.svn.core.SVNNodeKind
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 21: unable to resolve class org.tmatesoft.svn.core.wc.SVNStatusType
# line 21, column 1.
import org.tmatesoft.svn.core.wc.SVNStatusType
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 13: unable to resolve class org.tmatesoft.svn.core.io.SVNRepositoryFactory
# line 13, column 1.
import org.tmatesoft.svn.core.io.SVNRepositoryFactory
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 11: unable to resolve class org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory
# line 11, column 1.
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 15: unable to resolve class org.tmatesoft.svn.core.wc.SVNCommitClient
# line 15, column 1.
import org.tmatesoft.svn.core.wc.SVNCommitClient
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 18: unable to resolve class org.tmatesoft.svn.core.wc.SVNRevision
# line 18, column 1.
import org.tmatesoft.svn.core.wc.SVNRevision
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 22: unable to resolve class org.tmatesoft.svn.core.wc.SVNUpdateClient
# line 22, column 1.
import org.tmatesoft.svn.core.wc.SVNUpdateClient
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 23: unable to resolve class org.tmatesoft.svn.core.wc.SVNWCClient
# line 23, column 1.
import org.tmatesoft.svn.core.wc.SVNWCClient
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 8: unable to resolve class org.tmatesoft.svn.core.SVNPropertyValue
# line 8, column 1.
import org.tmatesoft.svn.core.SVNPropertyValue
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 14: unable to resolve class org.tmatesoft.svn.core.wc.ISVNStatusHandler
# line 14, column 1.
import org.tmatesoft.svn.core.wc.ISVNStatusHandler
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnClient.groovy: 9: unable to resolve class org.tmatesoft.svn.core.SVNURL
# line 9, column 1.
import org.tmatesoft.svn.core.SVNURL
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnScmProvider.groovy: 4: unable to resolve class org.tmatesoft.svn.core.wc.SVNWCUtil
# line 4, column 1.
import org.tmatesoft.svn.core.wc.SVNWCUtil
^
C:\Users\shravan64\.grails\2.1.0\projects\gurujiAatma\plugins\svn-1.0.2\src\groovy\grails\plugin\svn\SvnScmProvider.groovy: 3: unable to resolve class org.tmatesoft.svn.core.SVNAuthenticationException
# line 3, column 1.
import org.tmatesoft.svn.core.SVNAuthenticationException
While my colleague and I have still have not discovered the reason this is happening (the Release 1.0.1 and SVN 1.0.2 plugins are being pulled into this app despite no reference in any of the in-house plugins or app itself's application.properties or BuildConfig.groovy), we have discovered a make-shift solution.
In the failing app's BuildConfig.groovy, if you specify
build ":release:2.2.1"
as a dependency, and you run
grails uninstall-plugin svn
on your command line, you should be able to stay on Grails 2.1.0 and keep this compilation error from occuring.
I will update my answer here if I'm ever able to find out why the old release plugin was being pulled in as a dependency ( I had bombed my ~/.grails folder as well as my ~/.ivy2, so I really have no idea why it was being pulled in ).
I encountered this when first building a WAR file containing a reference to a plugin in my company's Grails SVN repository. I fixed it by adding the following to the dependencies section in BuildConfig.groovy, taken from the svn plugin's dependencies:
build("org.tmatesoft.svnkit:svnkit:1.3.5") {
excludes "jna", "trilead-ssh2", "sqljet"
}
It appears that the svn 1.0.2 plugin is not working well with grails 2.1.0. Downgrading to grails 2.0.4 seems to have resolved the issue.
I had checked out the project with svn 1.7 and had the exact same problem.
A friend mentioned svnkit is very sensitive about svn version. I removed the project and checked it out again with svn 1.6 and then it compiled with no issue.
Needless to say, I'll be moving this project to git ASAP. :)