The way to modularise a grails app is to create a plugin with the common components (domain objects, services etc), and then one or more web apps which use this. Easy and works.
The problem is that netbeans does not pick up the dependency, even though it is defined in the build.gralde file and the settings.gradle.
the project is created like this:
mkdir myproject
cd myproject
grails create-plugin core
grails create-app myapp
Now the following steps are taken to configure the project:
- create a "settings.gradle" in the projects root dir with the line "include 'myapp', 'core'"
Edit myapp/build.gradle and add the following section:
grails { plugins { compile project(':core') } }
Edit core/gradle.properties and add "exploded=true".
Now we can simply open core and myapp in netbeans and it picks them both up as grails projects.
Now we can create a domain object for example:
in core/grails-app/domain/me/core/User.groovy
package me.core
class User {
String first
String last
static constraints = {
}
}
in myapp/grails-app/controllers/me/admin/UserController.groovy:
package me.admin
import me.core.User // This import fails in the IDE!
class UserController {
static scaffold=User
}
Now you can do "grails run-app" in the myapp dir and your app runs and includes any classes from the plugin.
The file structure is like this:
myproject
settings.gradle
myapp
build.gradle
core
build.gradle
However, in netbeans UI, myapp can't "see" or resolve any of the plugins classes. It seems to have no awareness of settings.gradle nor the plugin dependency.
How do you add core as a dependency to the myapp project in netbeans? There is a "grails plugins" project context menu, and this has "reload plugins" and "new plugins", but both these items are empty (looks like they are broken).
Any ideas?