Jbehave with gradle - bdd

I am using Gradle in my project to run tests with Jbehave, and here are my dependencies:
dependencies {
testImplementation "org.jbehave:jbehave-core:4.6.3"
testImplementation "org.jbehave.site:jbehave-site-resources:3.3.1:#zip"
}
I searched on Jbehave website docs and I can't see any support for Gradle tasks, so how I can write a task to run tests with Jbehave and not using any specific plugin for that?

Related

run integration tests with external dependencies. gradle

I am new to the gradle tool and got next project.
TestNG tests with some classes, annotated with #Test.
buid.gradle where I got small script.
test {
dependsOn cleanReports
useTestNG() {
suites 'src/test/resources/testng.xml'
systemProperty "property1", System.getProperty("property1")
systemProperty "property2", System.getProperty("property2")
systemProperty "property3", System.getProperty("property3")
listeners << 'listener.BuildReportExecutionListener'
listeners << 'listener.TestResultListener'
}
}
I want to publish these tests to the artifactory, then In Jenkins use gradle clean test on jar file downloaded from artifactory to run specific release version of tests.
How can I do it?
You can build dynamic dependencies that are based on project properties.
https://discuss.gradle.org/t/dynamic-dependency-definitions-using-a-project-property-configuration/22773

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

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 can I include a dependant jar in a multi project grails / gradle build?

I have the following setup within my project...
A multi project gradle build for a SOA style project, wired together using rabbitmq and spring integration.
Contains a number of grails projects as well as plain java / groovy projects to represent the services.
Alongside each of the service projects are a project (jar) containing all of the public interfaces (and messages) for the service that can be proxied using spring integration.
The projects are related to each other using gradle dependencies and then I generate IntelliJ projects files using the gradle idea plugin.
What I want to do is:
Include the interfaces jar in the grails project so that I can use spring integration there to proxy my calls into the services via rabbitmq.
When I run the grails app have this intefaces jar built and included within grails.
When I run the grails app from IntelliJ have it compile the latest version of the interfaces and include them in the grails project.
When I build the entire project from gradle, have gradle correctly associate the interfaces jar with the grails app.
Ideally I would love to be able to do this just using dependency declaration within gradle, but this is probably a pipe dream...
What are my options?
Add a task into the grails build lifecycle within gradle to build any dependant jars and copy them into the grails lib folder?
Hook into the grails build lifecycle by using Events.groovy or similar to call out to grails to build and package the dependant jars. This would cover both the IntelliJ and command line routes.
Build the interfaces as a grails plugin? I had discounted this as they also need to be used from non-grails projects.
Any help / advice would be appreciated.
Turns out all I needed to do was add the following and then the grails plugin deals with the dependencies for me...
compile project(':dependent-project')
Works nicely for run-app and war...
A partial solution to the problem would be to use both Gradle and Grails maven plug-ins. I have a similar situation where I am building jars that are dependencies of the Grails project.
The approach I've chosen is to install the java artifacts into the local .m2/repo and then declare the dependency under grails/conf/BuildConfig.groovy using the mavenLocal() repo.
What I hadn't considered was to hook gradle into the events lifecycle (interesting idea, btw) and instead defined a gradle project that wraps the grails app (executes test-app, run-app, etc). The gradle wrapper for my grails app has a dependency on the other component's install task so it always checks to see if it needs to be rebuilt.
I'm an Eclipse user so I can't comment on the Intellij part of your question but the above works for me so I hope it gives you some ideas?
My solution for the moment is to:
Use the grails / gradle plugin to build the grails projects.
Use this plugin to run my grails apps, ie. gradle grails-run-app.
Hook into the grails-run-app task in gradle (which is created on the fly) to call a task which builds and copies the dependencies into the lib directory.
This doesn't help a whole load with IntelliJ at the moment but I will run my gradle tasks as IntelliJ run configurations.
My build.gradle is as follows (dependent-project is being jarred and put in lib in this example):
import org.grails.gradle.plugin.GrailsTask
evaluationDependsOn(':dependent-project')
buildscript {
repositories {
mavenCentral()
mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
}
dependencies {
classpath "org.grails:grails-gradle-plugin:1.1.1-SNAPSHOT"
}
}
repositories {
mavenCentral()
mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
}
ext {
version = "1.0"
grailsVersion = "2.2.0.RC2"
grailsTaskPrefix = "grails-"
}
apply plugin: "grails"
dependencies {
['dependencies', 'resources', 'core', 'test', 'hibernate', 'plugin-datasource', 'plugin-domain-class', 'plugin-tomcat', 'plugin-services'].each { plugin ->
compile "org.grails:grails-$plugin:2.2.0.RC2"
}
bootstrap "org.codehaus.groovy:groovy-all:2.0.5"
}
// Get hold of the grails-run-app task (which is created on the fly) and add a dependency to the copyDependencies task
project.gradle.afterProject { p, ex ->
if (p == project) {
project.tasks.addRule("Grails dependencies") { String name ->
if (name.startsWith(grailsTaskPrefix)) {
tasks.getByName(name).dependsOn(copyDependencies)
}
}
}
}
// Build and copy any dependent jar files...
task copyDependencies(type: Sync) {
from project(':dependent-project').configurations.archives.allArtifacts.files
into "$projectDir/lib"
}

Resources