1
votes

I didn't see anything that directly addressed my issue, I am sure it is simple since I am new at this and am having a hard time trying to get my head around what might be going wrong.

I created a simple plugin that has one, enum class in it. It is actually a working class copied from my existing application to the appropriate path in the plugin. The class is removed from the application. I build the plugin, install it and can see it doing grails list-plugins.

In my application I reference it (compile ":myplugin:1.0").

When I compile/run-app the application throws a compile error "unable to resolve class MyEnum".

All the plugin examples seem to indicate this should be easy. :/

So to summarize:

  1. grails create-plugin myplugin
  2. Move simple enum from another application path src/xxx/MyEnum.groovy to the plugin path src/xxx/MyEnum.groovy
  3. grails maven-install
  4. Alter BuildConfig of application to include compile ":myplugin:0.1"
  5. run-app... get compile error that the enum cannot be found (by a controller in the app that uses it).

Am I missing something major? I must be.

I am doing this in an attempt to see if I can separate out part of our domain objects into a plugin, along with some of their dependent classes.

---- UPDATE ----

Seems like a dependency issue. I am making incremental changes (to test as I go) with the plugin. I package and install it, but it seems like the grails app is not picking it up fresh even when I use refresh-dependencies. It seems like I am forced to increment the version number of the plugin with each change in order to get the application project to pick it up fresh?

2
Check to make sure your packages for where you are using your Enum and where the Enum are match, or that you import the Enum into wherever you are using it from in your application. - Joshua Moore
Thank you, I am. I duplicated the structure from the app itself. That's why I feel like it must be something simple I am missing... :/ - Tuishimi
after maven-install check the generated .zip file, if the file is in there. next check your target-folder, (e.g. with find) if there is something around. if in doubt change the version of the plugin and try again -- or delete previous version in your m2 local repo AND the ivy cache. also it is src/groovy/<package>/MyEnum.groovy, right? - cfrick
Yes... it is src/groovy/xxx/MyEnum.groovy. Sorry. The zip file looks alright to me, all the relevant sources, and under the target there is a class folder with the compiled class... (and other dependency type stuff). - Tuishimi
Under .grails/2.2.4/projects/myplugin I do not see the class anywhere. Should I try and force the plugin into my local maven repository instead of the .grails path? But wouldn't grails complain if it could not find the plugin? - Tuishimi

2 Answers

0
votes

The problem turned out to be the application not checking for updates to the dependencies. I did not find a proper solution, but since I am in a dev cycle I am simply updating a faux version value in the plugin and in BuildConfig.

0
votes

A few things you can try:

  • Ensure that you've imported the Enum class properly where you are using it.
  • If you've made updates to your plugin, reinstall the plugin using grails maven-install, then delete the compiled plugin from your target directory and run grails refresh-dependencies, or run grails clean-all and re-run grails refresh-dependencies.
  • When developing a plugin, in your test application try using a relative path in your BuildConfig.groovy to the plugin by adding the grails.plugin.location."plugin-name" = "/path/to/plugin". This will allow you to make changes to your plugin and they will immediately be available in your test application.