Search code examples
mavengrailsgroovybuildconfigggts

Grails plugin dependencies not available in application


Created a plugin in eclipse GGTS using Grails 2.3.8; standard plugin, no changes whatsoever, except for the following dependency (rabbitmq):

//BuildConfig (plugin)
plugins {
   compile(":rabbitmq:1.0.0")
   build(":release:3.0.1",
         ":rest-client-builder:1.0.3")         
}

Plugin dependencies were refreshed, compiled, and packaged, then stored in local maven repo as 'myplugin:mq:0.1', and verified.

Created Grails project, added plugin to project:

//BuildConfig (project)
plugins {            
   build ":tomcat:7.0.52.1"
   compile "myplugin:mq:0.5"  //<-plugin here

   compile ":scaffolding:2.0.3"
   compile ':cache:1.1.2'

   runtime ":database-migration:1.4.0"
   runtime ":jquery:1.11.0.2"     
}

Dependencies refreshed successfully.

Problem

I can't reference rabbitmq libraries or dependencies from the rabbitmq plugin from myplugin:mq

Not sure why the dependencies are not being inherited by the application, I'm not using exported = false or anything to suppress the plugins dependencies.

Tried

Instead of eclipse, I switched to command line (JDK 1.7 + 2.3.8, also tried 2.3.7), manually cleaned, refreshed, compiled, and still I can't resolve rabbitmq classes:

| Error Compilation error: startup failed:
C:\X-projects\ws-ggts_36\rest-api-doc-test\grails-app\controllers\org\raffian\restapi\controller\FundController.
 @ line 8, column 1.
   import org.springframework.amqp.rabbit.core.RabbitAdmin
   ^

Maven Local Deploy

I've altered group and artifact id:

mvn install:install-file  
    -Dfile=grails-test-plugin-0.5.zip
    -DgroupId=myplugin
    -DartifactId=mq
    -Dversion=0.5
    -Dpackaging=zip
    -DgeneratePom=true

Plugin Package Weirdness

After closer inspection of the packaged plugin, the ZIP contains just these files. I suspect this is the problem since the rabbitmq libraries are missing and, the plugin.xml or plugin descriptor contain no references to rabbitmq dependencies, so the application is not even aware of those dependencies. But why is the plugin not including its own dependencies?

enter image description here

Plugin Descriptor

class TestPluginGrailsPlugin {
    // the plugin version
    def version = "0.5"
    // the version or versions of Grails the plugin is designed for
    def grailsVersion = "2.3 > *"
    // resources that are excluded from plugin packaging
    def pluginExcludes = [
        "grails-app/views/error.gsp"
    ]

    def title = "Test Plugin Plugin" // Headline display name of the plugin
    def author = "Your name"
    def authorEmail = ""
    def description = 'desc'
    def documentation = "http://grails.org/plugin/test-plugin"
    def doWithWebDescriptor = { xml ->}
    def doWithSpring = {}
    def doWithDynamicMethods = { ctx -> }
    def doWithApplicationContext = { ctx -> }
    def onChange = { event -> }
    def onConfigChange = { event -> }
    def onShutdown = { event -> }
}

Solution

  • To publish a Grails plugin to local maven repo, use the command:

    grails maven-install
    

    from release plugin which is available to all newly created Grails plugin by default.

    Finally, here is how you can modify groupId of the plugin if required.