Accessing Internal Grails Modules

My team is suggesting modulating our current Grails project, so we experimented. We started doing this through IntelliJ:

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

      

Then, we move all the previously existing domain

, controller

, services

and view

in their specific module

.

When we launch the project (via MyProject run-app -reloading

), the pages that were previously available are returned error 404

. Now, of course, we think this is due to the restructuring of the project directory. We are trying to access these pages from this old one url

:

http://localhost:8080/MyProject/someController

      

to this new one url

, assuming it needs to add a namemodule

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

      

But it still doesn't work. How are we supposed to run the project with it and how can we access them? Do we need to customize some files .config

and .property

?

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 because our current Grails project can still be subdivided into smaller, independent projects (for maintainability, etc.). We have now managed to create (and run) these smaller projects. The problem arises when these smaller parts are consolidated. So the challenge is to create a parent Grails project (it's even possible).

+3


source to share


1 answer


It sounds like you are making the assumption that InteliJ modules are what Grails understands. This is not true.

The correct approach to building a modular Grails application is with "plugins". Grails has great support for creating your own plugins. You can even create built-in plugins that greatly speed up development. I highly recommend that you read the official documentation for creating and using plugins in a Grails application.

Keep in mind that your plugin may have almost all of the same artifacts as your application (services, domain classes, controllers, GSP, etc.), but will appear in the same application as if the application using the plugin , provided artifacts,

For example, if you have one BookController

in your plugin, it will have the same url mapping as if the controller were part of your base application. You indicate in your question that you want to have different urls for these controllers that your plugins provide. If this is the case, you need to register your controllers. You can find out more about this in the official documentation .



Update

To help visualize plugins working with modular Grails applications:

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

      

MyApp

- the main application (created with grails create-app

). It has its own functionality and includes both PluginA

and PluginB

(both created with grails create-plugin

) to add its own functionality to itself. You have the option to use built-in plugins, or even package plugins and publish them to your own internal repository for use by other applications ( MyApp

in this case). Please note that all three parts of this are separate. They can be changed independently, by version in your original control, managed, developed, etc.

+3


source







All Articles