Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.samueltbrown:gradle-cucumber-plugin:0.8'
}
dependencies {
implementation("com.github.samueltbrown:gradle-cucumber-plugin:0.8")
}
<dependency>
<groupId>com.github.samueltbrown</groupId>
<artifactId>gradle-cucumber-plugin</artifactId>
<version>0.8</version>
</dependency>
libraryDependencies += "com.github.samueltbrown" % "gradle-cucumber-plugin" % "0.8"
:dependencies [[com.github.samueltbrown/gradle-cucumber-plugin "0.8"]]
![Cucumber Logo] (https://cucumber.io/images/cucumber-logo.svg)
The gradle cucumber plugin provides the ability to run cucumber acceptance tests directly from a gradle build. The plugin utilizes the cucumber cli provided by the cucumber-jvm project and should support any of the languages utilized in cucumber-jvm.
(Currently only tested with Java, Groovy, and JRuby more coming soon!)
To use in Gradle 2.1 and later…
plugins {
id "com.github.samueltbrown.cucumber" version "0.9"
}
To use in earlier versions of Gradle…
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.github.samueltbrown:gradle-cucumber-plugin:0.9"
}
}
apply plugin: "com.github.samueltbrown.cucumber"
You can apply the plugin using the following buildscript
:
apply plugin: 'cucumber'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.samueltbrown:gradle-cucumber-plugin:0.6'
}
}
Older versions can be downloaded directly from GitHub like so;
buildscript {
apply from: 'https://github.com/samueltbrown/gradle-cucumber-plugin/raw/master/repo/gradle-cucumber-plugin/gradle-cucumber-plugin/0.3/cucumberinit.gradle'
}
Once the plugin has been applied, the project dependencies need to be updated with the cucumber-jvm jar file needed for your language. Below 'groovy' is the chosen language.
dependencies {
...
cucumberRuntime 'info.cukes:cucumber-groovy:1.2.2'
}
If you have a src/cucumber
source set (similar to src/test
), the plugin will automatically detect it and
setup Java tasks and configurations for you. The "cucumber" code unit depends on "test", the same way "test" depends on
"main". Also, choose your library dependencies:
dependencies {
cucumberCompile 'info.cukes:cucumber-groovy:1.2.2'
}
Write your feature files under src/cucumber/resources
.
Currently the plugin only supports one task to run your cucumber tests:
> gradle cucumber
The cucumber task has several configurable properties:
formats
: A list of output formats. (Defaults to <b>pretty</b>)glueDirs
: A list of directories where stepdefs and supporting code are located (Defaults to <b>src/test/java</b>)featureDirs
: A list of directories where feature files are located.(Defaults to <b>src/test/resources</b>)tags
: a list of the tags of the scenarios to run (['@a,~@b', '@c']
reads as (@a OR NOT @b) AND @c
)monochrome
: A boolean value indicating if console output should be one color. (Defaults to <b>false</b>)strict
: A boolean value indicating whether scenarios should be evaluated strictly. (Defaults to <b>false</b>)dryRun
: A boolean value indicating whether scenarios should be run as a dry run. (Defaults to <b>false</b>)jvmOptions {}
: a DSL block configuring the spawned process. Options are the same as for JavaExec.ignoreFailures
: A boolean value indicating whether failures from the cucumber runner should be ignored or not. Defaults to <b>false</b>cucumber {
formats = ['pretty','json:build/cucumber.json','junit:build/cucumber.xml']
glueDirs = ['src/test/resources/env',
'src/test/resources/support',
'src/test/resources/step_definitions']
featureDirs = ['src/test/resources/features']
tags = ['@billing', '@important']
monochrome = false
strict = false
dryRun = false
ignoreFailures = false
jvmOptions {
maxHeapSize = '512m'
environment 'ENV', 'staging'
}
}
You must use Cucumber version <b>1.1.6</b> or higher.
2.0
--plugin
rather than --format
arg for the cucumber runner when using cucumber-jvm 1.2.+
ignoreFailures
convention for test running.provided
scope.1.1.6
.As you would expect, clone, push to GitHub and create a pull request for us to review and merge.
Make sure you are using jdk 1.6 when running tests (jenv is our friend here).
./gradlew \
-Psigning.secretKeyRingFile=path/to/ring.gpg \
-Psigning.keyId=GPG_KEYID \
-Psigning.password=$GPG_PASS \
-PsonatypeUsername=$SONATYPE_USER \
-PsonatypePassword=$SONATYPE_PASS \
clean uploadArchives
It is possible to save some or all of those properties to ~/.gradle/gradle.properties
.