Sharing entities between App Engine modules

I am migrating from Eclipse to Android Studio and have a Android App connected to AppEngine. I have split the Server side into two modules (default module for Endpoints and user facing requests) and "admin" module for backend stuff. Now both these modules need to use the Entities. (backend module usually is responsible for saving these entities to DB, while the frontend default module is the one who returns data back to Android using these Entities).

What is the best way to share these Entity classes between these two modules in Android Studio? (also making sure these classes get enhanced etc). I do not wish to have duplicate classes, both in the default module as well as admin. Maybe have a common "java" module shared between the two (but not sure class enhancing would work). Or should the admin module NOT use the Entities and instead use other ways of persistence?

Appreciate your thoughts.


Solution 1:

While there may be reasons for not sharing the code, personally I prefer DRY.

I solved the issue in DRY spirit with the Python backend by placing the models definition file in the app dir app/models.yaml and sym-linking it into each of the modules subdirs app/module_blah/models.yaml, thus ensuring all modules see the same models definitions. At deployment time the symlinks are automatically replaced with the actual content of the file being symlinked. From appcfg.py update:

The command follows symlinks and recursively uploads all files to the server. Temporary or source control files, such as foo~, .svn/* are skipped.

Care may be needed to deploy all modules at the same time.

I used the same technique to also share entire libraries with common code across modules, by symlinking app/lib/libX subdirs into the desired app/module_blah/lib/libX as needed.

Not sure if this technique is usable in Java, tho.