How to use Gradle Cobertura plugin with Grails 3 - grails

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

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.

Grails 3 Code Coverage

I am using Grails version 3.0.4 on Windows 7. Does anyone know of a code coverage plugin or coverage tool that works for Grails 3? Thank you for your time.
I use Cobertura. It works fine for me.
My build.gradle entries for Cobertura:
// in buildScript
maven {
url "https://repo.grails.org/grails/core"
}
// in dependencies block
classpath "net.saliman:gradle-cobertura-plugin:2.3.0"
// in plugins
id "net.saliman.cobertura" version "2.3.0"
and then
apply plugin: "net.saliman.cobertura".
Since Grails 3.0 has migrated to Gradle for its build you should be able to use code coverage plugins available there. We have been using the Cobertura Gradle Plugin with good success where I work.

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.

Jenkins + Grails or Jenkins + Gradle + 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.

Grails Plugin Maven Integration

I'm trying to create Mavenized Grails application. Everything works fine but as I understood all the dependencies (all .jars like mysql-connector and also all grails (public) plugins like spring-security-core plugin) should be listed in pom.xml.
The thing is that I don't know how to include public grails plugins (is there any Maven repository for that, or should I include used plugins into my local repo?). Or is the proper way how to handle grails plugin to list them in "application.properties" and let the grails to manage these plugins?
Thank you for any comment.:-)
Mateo
You can specify your plugin dependencies in grails-app/conf/BuildConfig.groovy, for example:
grails.project.dependency.resolution = {
plugins {
runtime ':hibernate:1.2.1'
}
}
Update
In response to your comments below, a plugin dependency specified in BuildConfig.groovy (or application.properties) will still be resolved by Grails rather than Maven. I don't think there's any way that you can get Maven to resolve a Grails plugin dependency, because Maven can only work with JAR dependencies in Maven repositories. Remember, Grails plugins are not (typically) available from Maven repositories.
If you want to hand as much control as possible over to Maven, you can try excluding the JARs from your plugin dependencies, e.g.
plugins {
runtime( "org.grails.plugins:hibernate:1.2.1" ) {
excludes "javassist"
}
}
and add them to your pom.xml instead. Here be dragons (see below).
Editorializing
FWIW, unless you really have to build your Grails project with Maven (e.g. because another Maven project depends on it), my advice would be don't. I say this because Maven is very much a second-class citizen in the world of Grails build tools. The usual way to build a Grails app is using the built-in GAnt commands. Future versions of Grails will move towards Gradle as the default build tool, so it seems that Maven will be an afterthought for the forseeable future
By default, Grails plugins are included at the source level. A plugin zip is expanded, and the plugin source is compiled as part of the grails build process.
Since 2.0, grails can use binary plugins. You can depend on plain old JARS if those jars represent binary grails plugins.
Binary grails plugins can be referenced by normal maven coordinates.
Your project's BuildConfig.groovy is where you specify maven repositories and binary plugins.

Resources