Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing internal Grails modules

My team suggests to modularize our current Grails project, so we experimented. We've started doing it through IntelliJ:

Projects > MyProject _right-click_ New > Module ..... create-app

Then we move each previously existing domain, controller, services, and view to their specific module.

When we run the project (through MyProject run-app -reloading), the pages that previously were accessible returns error 404. Now of course, we believe that is because the project directory is restructured. We attempt to access those pages from this old url:

http://localhost:8080/MyProject/someController

to this new url, assuming that it only needs to append the module name

http://localhost:8080/MyProject/the-new-module-name/someController
                                ^ ^ ^ ^ ^ ^ ^ ^ ^ ^

But it still doesn't work. How do we suppose to run the project along with it's module and how can we access them? Do we need to configure some .config and .property files?

This is what the new project directory looks like:

MyProject
    +.idea
    + grails-app
    + lib
    .
    .
    .
    - the-new-module
        +.idea
        + grails-app
        + lib
        .
        .
        .
        + web-app
        + wrapper
    .
    .
    .
    + web-app
    + wrapper

edit: The reason the team wants to implement this "modular" approach is that our current Grails project can still be subdivided further into smaller, independent projects (for maintainability, etc.). Now, we have manage to create (and run) these smaller projects. The problem arises on consolidating these smaller pieces. So the task is to create a parent Grails project (is that even possible).

like image 245
Gideon Avatar asked Mar 08 '26 23:03

Gideon


1 Answers

It would appear you're making the assumption that InteliJ "modules" are something that Grails understands. It does not.

The correct approach to making a modular Grails application is "plugins". Grails has great support for creating your own plugins. You can even create inline plugins which greatly speed up development. I highly recommend you read the official documentation regarding plugin creation and use in your Grails application.

Keep in mind that your plugin can have almost all the same artifacts as your application (services, domain classes, controllers, GSPs, etc.) but will appear under the same application as if the application using the plugin was providing the artifacts.

For example, if you have the BookController in your plugin it will have the same URL mapping as if the controller were a part of your base application. You indicate in your question that you wish to have different URLs for these controllers which are provided by your plugins. If that's the case then you need to namespace your controllers. You can read more about that in the official documentation too.

Update

In order to help visualize how plugins work with modular Grails applications:

/~/MyApp 
/~/PluginA 
/~/PluginB

MyApp is the main application (created using grails create-app). It has it's own functionality and includes both PluginA and PluginB (both created using grails create-plugin) to add their functionality to itself. You have the option of using inline plugins or even packaging the plugins and publishing them to your own internal repository for use by other applications (MyApp in this case). Notice that all three parts of this are separate. They can be modified independently of one another, versioned in your source control, managed, developed, etc.

like image 119
Joshua Moore Avatar answered Mar 11 '26 15:03

Joshua Moore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!