22 Contributing to Grails - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 2.5.3
Table of Contents
22 Contributing to Grails
Grails is an open source project with an active community and we rely heavily on that community to help make Grails better. As such, there are various ways in which people can contribute to Grails. One of these is by writing useful plugins and making them publicly available. In this chapter, we'll look at some of the other options.22.1 Report Issues in JIRA
Grails uses JIRA to track issues in the core framework, its documentation, its website, and many of the public plugins. If you've found a bug or wish to see a particular feature added, this is the place to start. You'll need to create a (free) JIRA account in order to either submit an issue or comment on an existing one.When submitting issues, please provide as much information as possible and in the case of bugs, make sure you explain which versions of Grails and various plugins you are using. Also, an issue is much more likely to be dealt with if you attach a reproducible sample application (which can be packaged up using thegrails bug-report
command).Reviewing issues
There are quite a few old issues in JIRA, some of which may no longer be valid. The core team can't track down these alone, so a very simple contribution that you can make is to verify one or two issues occasionally.Which issues need verification? A shared JIRA filter will display all issues that haven't been resolved and haven't been reviewed by someone else in the last 6 months. Just pick one or two of them and check whether they are still relevant.Once you've verified an issue, simply edit it and set the "Last Reviewed" field to today. If you think the issue can be closed, then also check the "Flagged" field and add a short comment explaining why. Once those changes are saved, the issue will disappear from the results of the above filter. If you've flagged it, the core team will review and close if it really is no longer relevant.One last thing: you can easily set the above filter as a favourite on this JIRA screen so that it appears in the "Issues" drop down. Just click on the star next to a filter to make it a favourite.22.2 Build From Source and Run Tests
If you're interested in contributing fixes and features to the core framework, you will have to learn how to get hold of the project's source, build it and test it with your own applications. Before you start, make sure you have:- A JDK (1.6 or above)
- A git client
git clone http://github.com/grails/grails-core.git
Creating a Grails installation
If you look at the project structure, you'll see that it doesn't look much like a standardGRAILS_HOME
installation. But, it's very simple to turn it into one. Just run this from the root directory of the project:./gradlew install
GRAILS_HOME
installation. Note that this target skips the extensive collection of Grails test classes, which can take some time to complete.Once the above command has finished, simply set the GRAILS_HOME
environment variable to the checkout directory and add the "bin" directory to your path. When you next type run the grails
command, you'll be using the version you just built.Running the test suite
All you have to do to run the full suite of tests is:./gradlew test
BinaryPluginSpec
simply execute the following command:
./gradlew :grails-core:test --tests *.BinaryPluginSpec
Developing in IntelliJ IDEA
You need to run the following gradle task:./gradlew idea
Developing in STS / Eclipse
You need to run the following gradle task:./gradlew cleanEclipse eclipse
- Edit grails-scripts/.classpath and remove the line "<classpathentry kind="src" path="../scripts"/>".
- Add the springloaded-core JAR file in $GRAILS_HOME/lib/org.springsource.springloaded/springloaded-core/jars to grails-core's classpath.
- Remove "src/test/groovy" from grails-plugin-testing's source path GRECLIPSE-1067
- Add the jsp-api JAR file in $GRAILS_HOME/lib/javax.servlet.jsp/jsp-api/jars to the classpath of grails-web
- Fix the source path of grails-scripts. Add linked source folder linking to "../scripts". If you get build errors in grails-scripts, do "../gradlew cleanEclipse eclipse" in that directory and edit the .classpath file again (remove the line "<classpathentry kind="src" path="../scripts"/>"). Remove possible empty "scripts" directory under grails-scripts if you are not able to add the linked folder.
- Do a clean build for the whole workspace.
- To use Eclipse GIT scm team provider: Select all projects (except "Servers") in the navigation and right click -> Team -> Share project (not "Share projects"). Choose "Git". Then check "Use or create repository in parent folder of project" and click "Finish".
- Get the recommended code style settings from the mailing list thread (final style not decided yet, currently profile.xml). Import the code style xml file to STS in Window->Preferences->Java->Code Style->Formatter->Import . Grails code uses spaces instead of tabs for indenting.
Debugging Grails or a Grails application
To enable debugging, run:grails --debug-fork run-app
--debug-fork
argument causes the debugger to be associated with the forked JVM. In order to instead attach the debugger to the build system which is going to fork the JVM use the -debug
option:grails -debug run-app
22.3 Submit Patches to Grails Core
If you want to submit patches to the project, you simply need to fork the repository on GitHub rather than clone it directly. Then you will commit your changes to your fork and send a pull request for a core team member to review.Forking and Pull Requests
One of the benefits of GitHub is the way that you can easily contribute to a project by forking the repository and sending pull requests with your changes.What follows are some guidelines to help ensure that your pull requests are speedily dealt with and provide the information we need. They will also make your life easier!Create a local branch for your changes
Your life will be greatly simplified if you create a local branch to make your changes on. For example, as soon as you fork a repository and clone the fork locally, executegit checkout -b mine
Create JIRAs for non-trivial changes
For any non-trivial changes, raise a JIRA issue if one doesn't already exist. That helps us keep track of what changes go into each new version of Grails.Include JIRA issue ID in commit messages
This may not seem particularly important, but having a JIRA issue ID in a commit message means that we can find out at a later date why a change was made. Include the ID in any and all commits that relate to that issue. If a commit isn't related to an issue, then there's no need to include an issue ID.Make sure your fork is up to date
Since the core developers must merge your commits into the main repository, it makes life much easier if your fork on GitHub is up to date before you send a pull request.Let's say you have the main repository set up as a remote called "upstream" and you want to submit a pull request. Also, all your changes are currently on the local "mine" branch but not on "master". The first step involves pulling any changes from the main repository that have been added since you last fetched and merged:git checkout master git pull upstream
git checkout mine git rebase master
git checkout master git merge mine
git push
Say what your pull request is for
A pull request can contain any number of commits and it may be related to any number of issues. In the pull request message, please specify the IDs of all issues that the request relates to. Also give a brief description of the work you have done, such as: "I refactored the data binder and added support for custom number editors (GRAILS-xxxx)".22.4 Submit Patches to Grails Documentation
Contributing to the documentation is simpler for the core framework because there is a public fork of the http://github.com/grails/grails-doc project that anyone can request commit access to. So, if you want to submit patches to the documentation, simply request commit access to the following repository http://github.com/pledbrook/grails-doc by sending a GitHub message to 'pledbrook' and then commit your patches just as you would to any other GitHub repository.Building the Guide
To build the documentation, simply type:./gradlew docs
GRADLE_OPTS
environment variable a value like
export GRADLE_OPTS="-Xmx512m -XX:MaxPermSize=384m"
./gradlew -Dgrails.home=/home/user/projects/grails-core docs
grails.home
property, then the build will fetch the Grails source - a download of 10s of megabytes. It must then compile the Grails source which can take a while too.Additionally you can create a local.properties file with this variable set:
grails.home=/home/user/projects/grails-core
grails.home=../grails-core
./gradlew -Ddisable.groovydocs=true docs
build/docs
directory, with the guide
sub-directory containing the user guide part and the ref
folder containing the reference material. To view the user guide, simply open build/docs/index.html
.Publishing
The publishing system for the user guide is the same as the one for Grails projects. You write your chapters and sections in the gdoc wiki format which is then converted to HTML for the final guide. Each chapter is a top-level gdoc file in thesrc/<lang>/guide
directory. Sections and sub-sections then go into directories with the same name as the chapter gdoc but without the suffix.The structure of the user guide is defined in the src/<lang>/guide/toc.yml
file, which is a YAML file. This file also defines the (language-specific) section titles. If you add or remove a gdoc file, you must update the TOC as well!The src/<lang>/ref
directory contains the source for the reference sidebar. Each directory is the name of a category, which also appears in the docs. Hence the directories need different names for the different languages. Inside the directories go the gdoc files, whose names match the names of the methods, commands, properties or whatever that the files describe.Translations
This project can host multiple translations of the user guide, withsrc/en
being the main one. To add another one, simply create a new language directory under src
and copy into it all the files under src/en
. The build will take care of the rest.Once you have a copy of the original guide, you can use the {hidden}
macro to wrap the English text that you have replaced, rather than remove it. This makes it easier to compare changes to the English guide against your translation. For example:
{hidden} When you create a Grails application with the [create-app|commandLine] command, Grails doesn't automatically create an Antbuild.xml
file but you can generate one with the [integrate-with|commandLine] command: {hidden}Quando crias uma aplicação Grails com o comando [create-app|commandLine], Grails não cria automaticamente um ficheiro de construção Antbuild.xml
mas podes gerar um com o comando [integrate-with|commandLine]:
diff
will show differences on the English lines. You can then use the output of diff
to see which bits of your translation need updating. On top of that, the {hidden}
macro ensures that the text inside it is not displayed in the browser, although you can display it by adding this URL as a bookmark: javascript:toggleHidden();
(requires you to build the user guide with Grails 2.0 M2 or later).Even better, you can use the left_to_do.groovy
script in the root of the project to see what still needs translating. You run it like so:
./left_to_do.groovy es
{hidden}
blocks that hasn't changed since being translated will not appear in the diff output. In other words, all you will see is content that hasn't been translated yet and content that has changed since it was translated. Note that {code}
blocks are ignored, so you don't need to include them inside {hidden}
macros.To provide translations for the headers, such as the user guide title and subtitle, just add language specific entries in the 'resources/doc.properties' file like so:
es.title=El Grails Framework es.subtitle=...
<lang>
. will override the standard ones. In the above example, the user guide title will be El Grails Framework for the Spanish translation. Also, translators can be credited by adding a '<lang>.translators' property:
fr.translators=Stéphane Maldini
publishGuide_*
and publishPdf_*
tasks. For example, to build both the French HTML and PDF user guides, simply execute
./gradlew publishPdf_fr
build/docs/fr
. You can then view the translated guide by opening build/docs/<lang>/index.html
.All translations are created as part of the Hudson CI build for the grails-doc project, so you can easily see what the current state is without having to build the docs yourself.