Tuesday, May 6, 2014

Maven, App Engine and Yeoman

Over the last two years, Javascript's ecosystem of build/scaffodling/dependency management tools has really improved. These days it is quite easy to bootstrap and manage your app using Yeoman, for example.

Now I do use Javascript as the frontend language, but most of the time my backend is written in Java on Google App Engine, and uses good old Maven as the build and dependency management tool.

Luckily, there is a way to integrate Yeoman into the Maven package, you just have to use the yeoman-maven-plugin by Thomas Recloux. Here is how to integrate it in your pom.xml :


The next issue is, during development tasks, how do you wire your local development server (for example the App Engine local server or a Jetty instance) so that the "grunt server" command can leverage it ?

You can do this with the "proxy" feature in Grunt, you will find below what I added to my Gruntfile.js to make it work. You can also find the full example on Github.

The biggest issue I still have with this workflow is that I cannot keep the "grunt server" task running when I package my war, for example to upload on App Engine. Otherwise the Maven execution fails.

connect: {
            options: {
                port: 9000,
                // Change this to '' to access the server from outside.
                hostname: 'localhost',
                livereload: 35729
            }, proxies: [
                    context: [
                    host: 'localhost',
                    port: 8080,
                    https: false,
                    changeOrigin: false,
                    xforward: false
            ], livereload: {
                options: {
                    open: true,
                    base: [
                        '<%= yeoman.app %>'
                    middleware: function (connect, options) {
                        if (!Array.isArray(options.base)) {
                            options.base = [options.base];

                        // Setup the proxy
                        var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];

                        // Serve static files.
                        options.base.forEach(function (base) {

                        // Make directory browse-able.
                        var directory = options.directory || options.base[options.base.length - 1];

                        return middlewares;
grunt.registerTask('server', function (target) {
        if (target === 'dist') {
            return grunt.task.run(['build', 'connect:dist:keepalive']);


No comments:

Post a Comment