Search code examples
grailsgroovygradlegrails-plugin

Sharing domain objects between a grails application and a non grails application


I have a grails application with some domain objects which get serialized as JSON. In another java/groovy project, I would like to use these domain objects. If I publish a plugin, it looks like only other grails applications can use the plugin.

I tried to create a raw groovy project with the domain classes and their data, and in my grails app, I have stubs like this:

class Fact extends com.domain.Fact {}

When I go to run my app, however, I get these

Caused by MappingException: Missing type or column for column[facts_fact] on domain[DeclarationDefinition] referencing[com.domain.Fact]
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync

Is what I'm doing possible, or is there a better way?

At the end of the day, I want to be able to re-use POGOs as grails domain objects, or export grails domain objects as POGOs.


Solution

  • Duplicating the data model is going to be much simpler.

    And that level of service interdependence means you're doing services wrong.

    Version your services, and have APIs. Use JSON to communicate of an API, and don't try any wacky schemes to share a data model. If you're sharing a data model, you probably have one service, not two.