Jenkins + Grails or Jenkins + Gradle + Grails - grails

I have a grails project. I want to set up some CI for it. Are my better off calling grails commands directly from Jenkins or using Jenkins to call Gradle to call Grails commands.
The reason I ask is that when using Gradle with Grails most Gradle stuff just calls out directly to Grails commands.
Thanks

The easiest is to use the (built-in) grails wrapper (http://grails.org/doc/latest/guide/single.html#wrapper).
You would then run
./grailsw refresh-dependencies
./grailsw test-app
First line to setup (install all plugins etc.) grails and second to run your tests.
The advantage of grails wrapper is that it takes care of downloading & installing the correct grails version. Which is very useful if you upgrade grails. You don't have to do anything on your ci server.
There is also a grails plugin for jenkins (https://wiki.jenkins-ci.org/display/JENKINS/Grails+Plugin) that supports the grails wrapper.

Related

GRAILS --- what's the difference between commands grails war and gradle build?

I've heard you should type command
grails war
to build your project. I've thought to this point that Gradle is responsible for building the app in Grails. I've been doing the latter with conviction that my app is built. So what's the difference between
grails war
and
gradle build
?
Is it just that grails war is gradle build + create the war file?
It is not that simple to compare Grails and Gradle. Gradle is a build tool, while Grails is a web application framework.
However, Grails provides a command line tool, that's described in the docs:
Grails incorporates the powerful build system Gant, which is a Groovy wrapper around Apache Ant.
So, Grails does not use Gradle.
The basic usage of the grails command looks the following:
grails [environment]* [command name]
Where especially the command name parameter must be one out of predefined values. You can find the documentation on the war command here.
The basic usage of the gradle command looks the following:
gradle [option...] [task...]
The listed task parameters can be names of tasks created either in the build.gradle script or by plugins. All mentioned tasks and their respective task dependencies will be executed. If you use the Gradle War Plugin, it will generate a war task, which will also (transitively) be added as a task dependency of the build task. So whenever you call gradle build, a WAR file will be created. You can also call this task directly via gradle war.
EDIT
I just learned that Grails can or even does use Gradle beginning at a certain version. I even found a list on which Grails command calls which Gradle task. According to this list, calling grails war is equivalent to calling gradle assemble. The assemble task directly depends on the war task.
gradle build is a Gradle lifecycle task which usually consists of other tasks required to build a software like compileJava and other lifecycle tasks like assemble and check.
In case of Grails it delegates build to Gradle and to war task and it doesn't include check lifecycle during which unit tests will be executed.

How to use Gradle Cobertura plugin with Grails 3

I am trying to integrate the Gradle Cobertura plugin with my Grails application, but i seem to stuck in how i can hookup the plugin with my grails test-app runs.
I added the needed dependencies to the build.gradle file. So how can i use the plugin in the Grails application?
You can run Cobertura as Gradle Task as follows :
gradle cobertura
For more details on tasks provided by the Plugin, you may go through https://github.com/stevesaliman/gradle-cobertura-plugin/blob/master/usage.md

Equivalent to maven-install command in Grails 3

I have begun the journey of migrating my Grails apps to version 3.
I have a number of plugins that I with Grails 2 have installed to the local maven repository with the maven-install command available with the release plugin. They have then been easily accessible to my main project for import.
As far as I can see the release plugin does not exist for Grails 3. My question is, should I try to migrate the release plugin or is there some other, better way, in Grails 3?
If you have
apply plugin: 'maven-publish'
and the two apply from: 'https://raw.githubusercontent.com/... lines from the build.gradle file that's created for you when you create a Grails 3 plugin you can run
./gradlew install
to do the same thing as the maven-install script.

Grails fails if started with String parameter

I'm pretty new to the Grails Framework and I'm experiencing some strange behavior. If I use the grails commandline tool this way
grails "-DghprbPullTitle=Title with spaces" clean
grails fails with this error message
| Script 'With' not found, did you mean:
1) IntegrateWith
2) Init
3) CreateUnitTest
Starting grails this way will work
grails "-DghprbPullTitle=Title_without_spaces" clean
Ok one can now say "Then just avoid spaces" The problem is, that this occurs while I'm using Jenkins + Grails Plugin + Pull Request Builder Plugin. The Pull Request Builder Plugin generates some of these parameter with whitespaces.
Any thoughts how I can use grails with such whitespace-containing parameter. Or how I can tell the Pull Request Builder Plugin no to generate such parameter.
Maven on the other hand is able to handle such parameter.
Thanks in advance,
Marco
I ended up using shell builder with grailsw call instead of the Grails plugin.
Ok so it was a bug in the grails commandline tool. It will be fixed in grails 2.4-RC1.
See Grails Issue Tracker
The problem is that Grails Plugin + Pull Request Builder Plugin makes it pass build parameters from PR Builder plugin to grails commands. Those arguments with spaces are not required for build to happen, it's some kind of default in Grails Plugin to pass those parameters along to grails commands.
If Grails Wrapper on Grails Plugin didn't work for you, using Shell commands instead of Grails Plugin worked for me: it avoids parameters with space and makes GitHub notifications to work. It's worse for grails installations maintenance, but at least it's an alternative.
I submitted a PR https://github.com/jenkinsci/grails-plugin/pull/12 to work around this by suppressing the -D build environment variables.
I am using the Github pull request builder plugin https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin to run test-app and was running into the same issues as others. I am not using any of the variables that the ghprb plugin passes in so I added an option to suppress -D build environment variables. When this option is checked none of the -D variables are passed to grails allowing the build with grails plugin to run the targets as expected.
If you want to test it out to see if it works for you, you can download it from here http://jmoses.co/data/grails.hpi and install it manually How to install a plugin in Jenkins manually?

How do I know what webserver gradle / grails is using?

This thread: Gradle / Grails application describes how to set up the grails plugin for gradle.
The command gradle grails-run-app tries to start the grails application on port 8080. What webserver is gradle using here?
Does it have an embedded one? If so how can I access / configure it?
It just shelling out to the same thing that Grails would have done without Gradle, as if you had run grails run-app. That depends on which server plugin you have installed. By default it's http://grails.org/plugin/tomcat, but you can switch to http://grails.org/plugin/jetty by changing the values in grails-app/conf/BuildConfig.groovy
Gradle is nothing but a build and config tool like maven. When you use it with Grails app the dependencies are managed by it as it happens when maven is used.
When you use gradle grails-run-app it does nothing more other than running grails run-app from its own context. The same embedded Tomcat server is used by default.

Resources