I am a beginner of Grails.
I'd like to use memcached in Grails, I have tried with reference to the following.
http://www.ibm.com/developerworks/java/library/j-memcached2/index.html
Download the jar, I put the lib folder the jar.
Then run-app, I found the error.
Error Message
/grails-app/services/MemcachedService.groovy: 1: unable to resolve class net.spy.memcached.AddrUtil
# Line 1, column 1.
import net.spy.memcached.AddrUtil
^
/grails-app/services/MemcachedService.groovy: 2: unable to resolve class net.spy.memcached.MemcachedClient
# Line 2, column 1.
import net.spy.memcached.MemcachedClient
^
2 errors
I have written on the page that I referred to, and just put the lib folder the jar.
I wonder that must be set in addition to it?
Please help me.
Grails version: 2.1.2
spymemcached version: 2.8.4
OS: CentOS
You're better off adding a dependency in BuildConfig.groovy. Let Grails download it once for you and cache it so you can use it in multiple projects.
Add http://files.couchbase.com/maven2/ as a custom repository:
repositories {
grailsPlugins()
grailsHome()
grailsCentral()
mavenRepo 'http://files.couchbase.com/maven2/'
}
and then add the dependency for spymemcached:
dependencies {
compile 'spy:spymemcached:2.8.9'
}
If you do need to use a jar file (e.g. if it's not available in a public repo) put it in the lib directory but you need to run grails compile --refresh-dependencies to get the file recognized and added to the application's dependencies.
Related
I'm trying to install Perf4J Integration Plugin for Grails.
I've added compile ":perf4j:0.1.1" on my BuildConfig.groovy but when I try to refresh my dependencies I get:
Fatal error during compilation org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/me/Programs/test/target/work/plugins/perf4j-0.1.1/./Perf4jGrailsPlugin.groovy: 5: unable to resolve class org.perf4j.log4j.Log4JStopWatch
# line 5, column 1.
import org.perf4j.log4j.Log4JStopWatch
^
/home/me/Programs/test/target/work/plugins/perf4j-0.1.1/./Perf4jGrailsPlugin.groovy: 2: unable to resolve class org.codehaus.groovy.grails.plugins.support.GrailsPluginUtils
# line 2, column 1.
import org.codehaus.groovy.grails.plugins.support.GrailsPluginUtils
^
2 errors
(Use --stacktrace to see the full trace)
...
The second error is happens because GrailsPluginUtils has changed package from org.codehaus.groovy.grails.plugins.support to org.codehaus.groovy.grails.plugins. I've found a fixed version on the a Github fork.
But even when I try to compile the plugin sources downloaded from the Github repository linked above, I still get the org.perf4j.log4j.Log4JStopWatch.
Does anyone has any idea how to solve it?
I guess your grails application still caches the old version of perf4j. You mentioned about the repository in github where we had cloned, fixed the missing packages and bumped the version to 0.2.1.
In my experience, we did some works:
clone, then either install it into the local maven repository or deploy to your owned company maven centre. For us, we deploy per4j to EBI maven repository.
If you would go with our deployment of per4j, you need to add compile ":perf4j:0.2.1" inside plugins section and add mavenRepo "http://www.ebi.ac.uk/~maven/m2repo" under repositories section of BuildConfig.groovy located in grails-app directory.
How this would help you sort the issue out.
I'm converting an existing Maven based project containing a Grails 2.4.2 application to Gradle 2.6 and Grails 3.0.4. It's a mixed environment with Java, Groovy, and Grails used in several sub-projects. I've converted all the pom.xml files into build.gradle files, starting off with ./gradlew init, and then hand editing as needed. Before converting the Grails project's grails-app/conf/BuildConfig.groovy to the build.gradle equivalent, everything built fine with Gradle 2.6. After I converted the Grails project's BuildConfig.groovy file to build.gradle, I'm getting the following error when trying to run ./gradlew build:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':foo:runtime'.
> Could not find json-lib-jdk15.jar (net.sf.json-lib:json-lib:2.4).
Searched in the following locations:
file:/Users/xyz/.m2/repository/net/sf/json-lib/json-lib/2.4/json-lib-2.4-jdk15.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
The json-lib-2.4.jar file does exist in the local M2 cache shown above, but it doesn't have the -jdk15 part in it. There's no explicit dependency to any json-lib jar file in the build.gradle file for the Grails project. A parallel project does have an explicit dependency on this library, but that project builds fine. I've tried to explicitly add the dependency to the build.gradle file in the Grails project both with and without "classifier: 'jdk15'" to the dependency declaration. When I ran ./gradlew dependencies, I noticed that an older version (2.3) of the json-lib jar file showed up in the list as an implied dependency for some Apache HttpComponent stuff. I then tried both versions of this in the allProjects section of the top level build.gradle:
configurations {
all*.exclude module: 'json-lib'
}
as well as:
configurations {
all*.exclude module: 'json-lib', classifier: 'jdk15'
}
Neither variant makes any difference. I'm really stuck on this and would appreciate any tips on how to move forward. In case it makes a difference, I'm running this on a Mac with MacOS 10.10.5, the JDK version is 1.8.0_25-b17. Thanks.
dependencies {
//compile group: 'net.sf.json-lib', name: 'json-lib', version: '2.4'
compile "net.sf.json-lib:json-lib:2.4:jdk15"
}
tl;dr version
Dependencies of my custom grails plugin weren't getting inherited and resolved by projects I installed the plugin to.
Install the latest version of the release plugin to your plugin (fixes the issue for jar dependencies)
Clear out any references to plugins that might exist in your BuildConfig.groovy file (fixes the issue for plugin dependencies)
grails maven-install to make the plugin available in the mavenLocal() source
Long version
So, I've been trying to create a custom grails plugin for internal use at my University.
I'd really like it if putting the plugin in your BuildConfig.groovy file's plugins closure would automatically install not just the plugin, but all the dependencies defined for the plugin in its BuildConfig.groovy file (or, after packaging, its dependencies.groovy file).
Looking at the instructions, I have setup the BuildConfig.groovy file for my project with this in the repositories closure:
flatDir name:'my-plugin', dirs:'/Users/me/workspace-ggts/myplugin'
Then added this to the plugins closure:
compile(":grails-my-plugin:0.1")
That does install the plugin correctly, but it doesn't resolve any of the plugin's dependencies or needed plugins. Here's the three main closures in the plugin's BuildConfig.groovy file:
repositories {
grailsCentral()
mavenCentral()
mavenRepo "http://www.mygrid.org.uk/maven/repository"
def jbossResolver = new org.apache.ivy.plugins.resolver.URLResolver()
jbossResolver.addArtifactPattern("https://repository.jboss.org/nexus/content/groups/public-jboss/com/sun/media/[module]/[revision]/[artifact]-[revision].[ext]")
jbossResolver.addArtifactPattern("https://repository.jboss.org/nexus/content/groups/public-jboss/javax/media/[module]/[revision]/[artifact]-[revision].[ext]")
resolver jbossResolver
}
dependencies {
compile (
[group:'javax.media', name:'jai-core', version:'1.1.3'],
[group:'com.sun.media', name:'jai-codec', version:'1.1.3']
)
compile "net.java.dev.jai-imageio:jai-imageio-core-standalone:1.2-pre-dr-b04-2013-04-23" //this jar comes from the mygrid mavenRepo
}
plugins {
build(":tomcat:$grailsVersion",
":release:1.0.0") {
export = false
}
compile ":spring-security-core:1.2.7.3"
compile ":wslite:0.7.2.0"
}
If I run the plugin using grails run-app, it resolves all of those dependencies just fine. It's only when the plugin is installed to a project that automatic dependency resolution fails.
I've tried making the plugin a maven artifact, and copying it to my local repository. In those cases, I removed the flatDir line from the repositories closure and replaced it with mavenLocal(). Again, the plugin itself installs, but none of the specified dependencies do.
I've tried setting legacyResolve in BuildConfig.groovy to true, but this also fails to install either the jars or the needed plugins (like wslite).
I even tried manually specifying compile(":grails-my-plugin:0.1") {transitive: true}, but it still won't resolve the plugins.
Between all of the above attempts I've uninstalled my plugin, run grails clean on the project, deleted the contents of the ~/.grails/2.2.3/cached-installed-plugins/ directory, and poured libation while intoning the holy name of Burt Beckwith, but I still can't get transitive resolution.
One other noteworthy thing: I've run a dependency-report on the project. It lists my plugin among the dependencies, but the report says that the plugin itself has no dependencies.
I also ran refresh-dependencies myAppDeps.xml in order to get a dependency report. It contains none of the plugin's dependencies that aren't also dependencies of a vanilla grails project.
Grails plugins in the public repositories get their dependencies resolved automagically (try putting spring-security-ldap in your BuildConfig.groovy file as an example, and spring-security-core will install). Does transitive resolution simply not work for local plugins? Are there any ways to make it work, like tacking something into _Install.groovy?
Update
So, I tried dmahapatro's suggestion. That did work for getting the jars on which myPlugin depends installed in the project; thus, the project compiles and the dependency report contains the needed jars. However, the plugins that myPlugin depends on are still not getting installed into the projects that I install myPlugin too. When I try to run the app after a successful compilation, I get this error:
| Error Error: The following plugins failed to load due to missing dependencies: [myPlugin]
- Plugin: myPlugin
- Dependencies:
- springSecurityCore (Required: 1.2 > *, Found: 1.2.7.3)
- jquery (Required: 1.7 > *, Found: 1.8.3)
! wslite (Required: 0.7.2 > *, Found: Not Installed) [INVALID]
Further Update
So, I decided to try to isolate the problem. I created a fresh plugin (grails create-plugin transitiveDep), and a fresh project (grails create-app horseradish). I copied the relevant portions of BuildConfig.groovy from my working projects into each, changing the plugin dependency from my-plugin to transitive-dep.
Lo and behold, horseradish successfully installed all the needed dependencies (wslite, springSecurityCore). It even asked if I wanted to install the older version of jQuery.
So, nothing is wrong with my environment. I suspect at this point that something else is wrong with the plugin's configuration. It was originally written in Grails 2.0.1, then upgraded to 2.2.3. I've also tried installing it into a fresh app, just like I did my transitive-dep plugin, but with it still failed to resolve plugin dependencies. I'll post an update when I've figured out exactly where the issue is.
Final Update
So, the thing keeping the plugins from installing was that myPlugin referenced them in the application.properties file as well as BuildConfig.groovy. If I deleted the references to them there before packaging, the plugin installed just fine.
I also noticed that I still had the old Grails version (2.0) in myPluginGrailsPlugin.groovy file, as well as a dependsOn map that doesn't seem to be needed anymore. I removed/altered those lines, but it wasn't until clearing out the old references in application.properties that things really started working.
Notably, I also had to clear out my ~/.grails/2.2.3, ~/.grails/ivy-cache folders, and ~/.m2/repository/org/grails/plugins/ directories after making changes to myPlugin, or my projects would still try to install the old versions. I got so tired of doing that, I made a shell script to do it:
cd ~/.grails/2.2.3/
rm -r *
cd ~/.grails/ivy-cache/
rm -r *
cd ~/.m2/repository/org/grails/plugins/
rm -r *
Important actions to note and rectify (w.r.t Grails 2.2.3):
Check your application.properties file. There should not be any reference to installed plugins in application.properties. If you had been installing plugins using the install-plugin command (which I discourage now since it will no longer be available), they were likely be written to that file. Delete any lines referencing installed plugins before you do a grails refresh-dependencies and grails maven-install.
Upgrade release plugin inside your plugin to v2.2.1
as below if you are using latest version of grails.
......
build(":tomcat:$grailsVersion",
":release:2.2.1") {
export = false
}
.......
When you do grails maven-install on the plugin, the resultant zip created will be named as grails-my-plugin.zip if the plugin project name is MyPlugin, but when you refer the plugin in your grails application (retrieving from .m2 local repo), you have to refer the plugin as
compile ':my-plugin:0.1' //instead of "grails-my-plugin"
Observation:
I was facing issues (related to svn plugin) using release:1.0.0 (deliberately downgraded to replicate your issue) when testing so it is a better idea to upgrade to version 2.2.1 if you are using Grails 2.2.* etc. You would not be able to use v3.0.0 unless you use Grails 2.3 as mentioned in the doc.
It did not complain anything when I used mygrid repo while testing. [http://www.mygrid.org.uk/maven/repository]
Once my-plugin was added to my application I was able to compile my app where it installed spring security core referred from my-plugin.
Dependency report showed the transitive dependencies as well.
Tested in Grails 2.2.3
on the plugin project run package-plugin. it will generate the dependency file for you. Than you should not get this dependency issue.
I had a similar issue of application not detecting transitive dependencies from plugin.
My plugin's grails version was 2.3.4 and the app that used the plugin was 2.1.0.
The plugin was packaged using grails publish-plugin and manually uploaded to a private Maven compatible repository(Artifactory).
Grails 2.3.4 doesn't generate dependencies.groovy and the app didn't figure out the transitive dependencies and failed compilation.
As #rittinger mentioned in this post custom-plugin-dependencies-groovy-is-ignored pom does the trick. When I manually uploaded the plugin.zip file to Artifactory, it generated a pom file which didn't have a <dependencies/> section.
But when I followed the release plugin instructions and uploaded the plugin to Artifactory, the generated pom file had <dependencies/> section. Afterwards the App didn't have any problems resolving transitive dependencies.
I'm a grails newby. I am using grails 2.0.3 from the command line (no IDE) on windows 7.
I am just running the 'hello world' example from the grails documentation.
I have a custom jar that is not in maven that I would like to use in my project. I added it to the lib folder and did a refresh-dependencies. I modified the controller to import a class from the jar. When I did 'run-app', the compiler complained that it could not find the class.
I saw several example online where people had to add a line to their BuildConfig.groovy like this: runtime 'httpclient:httpclient:3.0.1' . But since I'm not using maven or ivy, how do I get that jar on my classpath?
The example I am referring to above is http://grails.1312388.n4.nabble.com/External-Jar-in-Grails-td4388010.html
Grails 2.0-2.2
Ok, I finally figured out what I need to do. Suppose my jar is named 'mylib.jar'. I need to rename it to mylib-1.0.jar and move it to the lib directory. Then I need to add the following to BuildConfig.groovy:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.16'
runtime 'mylib:mylib:1.0'
}
I guess that was obvious to everyone but me. Hope this helps someone else.
Grails 2.3-...
Just put a jar into the lib/. Do not modify BuildConfig.groovy (c) kaskelotti
if your jar is in lib folder and also entry in buildconfig.groovy and if you can't find jar in your build path then try to use below command.
grails compile --refresh-dependencies
I don't understand maven or grape, and I'm an idiot so give me the step by step if your answer is "go grap X-dependency manager and then rtfm and you're set." Where do i find and dump files to make this line work:
import groovyx.net.http.HTTPBuilder
It says Groovy: unable to resolve class groovyx.net.http.HTTPBuilder
Also I am unable to import groovyx.net.http.ContentType.URLENC It says unable to resolve class groovyx.net.http.ContentType.URLENC
Update:
apparently you can uncomment the line mavenRepo "http://repository.codehaus.org" in BuildConfig.groovy
Since you're talking about BuildConfig.groovy I assume the question is targeted at using HttpBuilder in a grails application. If so, you could either use
compile('org.codehaus.groovy.modules.http-builder:http-builder:0.5.0') {
excludes "commons-logging", "xml-apis", "groovy"
}
in the dependencies-section of BuildConfig.groovy, or, even more easier, just install the rest plugin:
grails install-plugin rest
try importing the .jar for HTTPBuilder-http://repository.codehaus.org/org/codehaus/groovy/modules/http-builder/http-builder/0.5.2/
Thom Nichols actually provided a helpful answer at http://groovy.329449.n5.nabble.com/problem-running-http-builder-code-td3995735.html to a similar question.
Basically, you can get into one of the snapshot directories at http://snapshots.repository.codehaus.org/org/codehaus/groovy/modules/http-builder/http-builder/ and download one of the packages ending with 'all'. Inside there, you'll find a dependencies directory that contains all the dependencies you need, which you can place in your lib directory. The root of the all zip (or tar) file should contain the main http-builder-#.#-SNAPSHOT.jar, which you should also place in lib.
I was doing this just from the Groovy Console. For Grails, I imagine Stefan's answer of just installing the Grails rest plugin is the best bet.