grailsbuildnative-codecustom-build-step

grails including native code


I have a grails project that depends on some native code, which will vary depending on the platform. I would like store these in my dependency repository (e.g. nexus), rather than in the project directly since they are files that can be shared across multiple projects (it is 3rd party native code).

I start my app using grails -Djava.library.path=/path/to/native run-app

But I need a way to copy the appropriate native code (based on the platform) to /path/to/native

I've done this in a desktop application using maven, where I included a custom build step that copies the platform specific native code to /path/to/native, but I'm not sure how to do this in grails. Is creating a custom _Events.groovy the right approach or is there other ways to add this custom build step?


Solution

  • Grails can use regular Maven dependencies by declaring them in the dependencies {} block in BuildConfig.groovy, and these will get copied into the WAR during the build. There's no need to include the library binaries in your Grails application source.

    _Events.groovy is the appropriate place to add scripts to hook into the build process.