Showing posts with label grails. Show all posts
Showing posts with label grails. Show all posts

Friday, July 26, 2013

Review of the Grails Gradle Plugin

UPDATE: Using the bootstrap configuration for the Tomcat plugin excludes it from the grails-war task.

See https://github.com/grails/grails-gradle-plugin/pull/43


Gradle support for Grails is maturing slowly and I must say that I can't wait for Grails 3.0. "Oh yeah, I'm excited!" :-), almost.

There are still few bits that I'm not clear about though in terms of how tight the integration will be, not specifically from an IDE usage perspective.

I watched a presentation from Luke Daley (aka alkemist) on Youtube(gr8conf 2013). It showcased the Gradle plugin for building Grails applications using the grails-gradle-plugin.

I was able to create a small POC and I want to share that experience with you.

General notes

Building a war and running Grails commands? Not a problem.
gradle grails-run-app
gradle grails-war

You can configure the Grails environment using -PgrailsEnv as command line argument.
-Dgrails.env= or -Pgrails.env= doesn't seem to work.

Arguments can be specified using -PgrailsArgs
gradle -PgrailsArgs='com.Domain' grails-create-domain-class

For some reason, the grails-gradle-plugin seems to require a closure with a Grails version specified twice (assuming that version is only used for bootstrapping the initial call??, while grailsVersion is used for building). I think that it should probably be consolidated...

grails {
  grailsVersion '2.2.3'
  version '2.2.3'
}

Below is a build.gradle file that does work for the Grails Gradle plugin 2.0.0-SNAPSHOT. Dump the file into some folder and run gradle init first.

buildscript {
  repositories {
    mavenCentral()
    maven { url 'http://repository.jboss.org/maven2/' }
    maven { url 'http://repo.grails.org/grails/repo' }
    maven { url 'http://repo.grails.org/grails/plugins' }
    maven { url 'http://repository.springsource.com/maven/bundles/release' }
    maven { url 'http://repository.springsource.com/maven/bundles/external' }
    maven { url 'http://repository.springsource.com/maven/libraries/release' }
    maven { url 'http://repository.springsource.com/maven/libraries/external' }
  }

  dependencies {
    classpath 'org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT',
    'org.grails:grails-bootstrap:2.2.3' 
  }
}

version='0.0.1'

apply plugin: 'grails'

repositories {
  mavenCentral()
  maven { url 'http://repository.jboss.org/maven2/' }
  maven { url 'http://repo.grails.org/grails/repo' }
  maven { url 'http://repo.grails.org/grails/plugins' }
  maven { url 'http://repository.springsource.com/maven/bundles/release' }
  maven { url 'http://repository.springsource.com/maven/bundles/external' }
  maven { url 'http://repository.springsource.com/maven/libraries/release' }
  maven { url 'http://repository.springsource.com/maven/libraries/external' }  
}

grails {
  grailsVersion '2.2.3'
  version '2.2.3'
}

configurations {
  all {
    exclude module: 'commons-logging'
    exclude module: 'xml-apis'
  }
  test {
    exclude module: 'groovy-all'
  }
  compile {
    exclude module: 'hibernate'
  }
}

dependencies {
  compile( "org.grails:grails-crud:$grails.grailsVersion",
           'org.grails:grails-gorm:1.3.7')

  bootstrap "org.grails:grails-plugin-tomcat:$grails.grailsVersion"
}

Saturday, May 11, 2013

Build Tools Wrappers

Today I stumbled upon a new project called maven-wrapper.
I haven't tested it myself, but it looks like a very promising effort. Users/Developers will be able to perform builds without an existing Maven installation.

Grails and Gradle already have a way to generate wrappers.
Antw seems similar to gvm in terms of concepts and approach.

Those tools wrappers allow users to build programs without having the software already installed on their local machines.

This is particularly interesting for build servers, and more specifically continuous integration servers:
  • Many projects may require different versions of a build tool.
  • Sometimes the setup of the build tools on a server involves following many processes and getting couple of approvals.
  • There's a risk of human error that will result into a corrupted non-working software installation (i.e. moving few files around to follow corporate conventions -> broken scripts, file permission issues, etc.).

There are often issues related to build tools in terms of software distribution and usage:
  • People got a copy of the source code, but they don't know how to build it.
  • The user knows the build tool to use, but he doesn't know how to set it up (Environment variables, PATH manipulation, etc.)
  • The user knows how to setup the build tool and build the application, but not how to configure the project inside an IDE
  • etc.

I expect more and more build tools (as well as full-stack frameworks) to provide the ability to generate seamless wrappers, as it is a very convenient feature.

Saturday, December 08, 2012

emacs-grails-mode enhancements

I'm now using Emacs again as my main Anything (Text Editing, Mail Reading, Blogging, Chat, etc.).

I still use vi and IDEs randomly but I will dedicate more time to master Emacs (don't quote me on that...) and a bit of Lisp.

I was looking for some Emacs packages for Grails Development and I found emacs-grails-mode.
It's nice, but it doesn't seem to provide few things such as running a random Grails command against a project.

During development, most of the time I'm jumping between files using find-file-in-project. Occasionally, I use few functions provided by emacs-grails-mode to switch between files associated to Grails domain classes.

Then, whenever I want to run a Grails command, I switch to a dedicated shell buffer. I read the output and I jump back to the file(s) that I'm working on...

I'm no Lisp coder which is a bit sad from my perspective. If I were fluent with it, I could write couple of Emacs packages or improve few things for my personal taste.


Below is my first attempt to improve emacs-grails-mode. I will soon create a basic project on my corporate GitHub account and push the code there. The license will be GPL v3.

I added the following extensions to emacs-grails-mode.
  • Few functions to run some Grails commands from the project folder.
  • There are are also 3 functions to browse API docs, Wiki docs as well as the latest reference guide.


;; ================================
;; Extensions for grails-mode
;; Author : Yves Zoundi
;; Created : 08-Dec-2012
;; 
;; License: GNU GPL v3 (http://www.gnu.org/licenses/gpl-3.0.txt)
;; Sypnosis:
;;    Run grails command on a project
;;
;; TODO:
;;   - Add some easy keybindings like in Rinari
;;   - Would be nice if auto-completion was there
;;     (including dynamic methods)
;;   - Anything else that would be useful for Grails development
;; ================================
(require 'grails-mode)

;; --------------------------------
;; Main functions
;; --------------------------------
(defun grails/command (str)
  "Run a Grails command (Non interactive)"
  
  (project-ensure-current)
  (setq shell-command-initial-directory 
        (project-default-directory (project-current)))
  ;; store old directory
  (setq old-dir default-directory)

  (setq command-initial-directory 
        (expand-file-name shell-command-initial-directory))
  (cd command-initial-directory)
  
  ;; runs the grails command from the project directory
  (async-shell-command (concat "grails " str) nil nil)

  ;; restore previous directory
  (cd old-dir)
  )

 (defun grails/read-param-and-run (input-hint grails-command)
  "Read an input parameter and invoke a given Grails command"
  (setq grails-command-argument 
        (read-from-minibuffer input-hint))  

  (grails/command 
        (concat grails-command " " grails-command-argument))
 )

;; --------------------------------
;; General functions
;; --------------------------------
(defun grails/icommand ()
  "Enter a Grails command (Interactive)"
  (interactive)  
  (grails/read-param-and-run "Goal:" "")
  )

(defun grails/create-domain ()
  "Create a Grails Domain Class"
  (interactive)
  (grails/read-param-and-run 
   "Domain class:" "create-domain-class")
  )

(defun grails/create-controller ()
  "Create a Grails Controller"
  (interactive)
  (grails/read-param-and-run 
   "Controller Domain class:" "create-controller")
  )

(defun grails/create-service ()
  "Create a Grails Service"
  (interactive)
  (grails/read-param-and-run 
   "Service Domain class:" "create-service")
  )

(defun grails/create-taglib ()
  "Create a Grails Taglib"
  (interactive)
  (grails/read-param-and-run 
   "TagLib Name:" "create-tag-lib")
  )

;; --------------------------------
;; Plugin functions
;; --------------------------------
(defun grails/install-plugin ()
  "Install a Grails plugin"
  (interactive)
  (grails/read-param-and-run 
   "name optionalversion:" "install-plugin")
  )

(defun grails/uninstall-plugin ()
  "Uninstall a Grails plugin"
  (interactive)
  (grails/read-param-and-run 
   "Plugin Name:" "uninstall-plugin")
  )

(defun grails/package-plugin ()
  "Package a Grails plugin"
  (interactive)
  (grails/command "package-plugin")
  )

(defun grails/refresh-dependencies ()
  "Refresh Grails Dependencies"
  (interactive)
  (grails/command "refresh-dependencies")
  )

;; --------------------------------
;; Browse docs (api, wiki, guide)
;; --------------------------------
(defun grails/browse-wiki-docs ()
   "Browse the Wiki Documentation"
   (interactive)
   (browse-url "http://grails.org/Documentation")
)

(defun grails/browse-api-docs ()
   "Browse the API Documentation"
   (interactive)
   (browse-url "http://grails.org/doc/latest/api/")
)

(defun grails/browse-latest-guide ()
   "Browse the official Grails Guide"
   (interactive)
   (browse-url "http://grails.org/doc/latest/guide/single.html")
)

(provide 'emacs-grails-mode-ext)