cucumber dependencies
implementation group: 'io.cucumber', name: 'cucumber-spring', version: '7.5.0'
implementation group: 'io.cucumber', name: 'cucumber-java', version: '7.5.0'
//implementation group: 'io.qameta.allure', name: 'allure-cucumber7-jvm', version: '2.20.1'
Gradle task
task cucumber(type: Test) {
logger.lifecycle("Run cucumber gradle task. ")
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
var cucumberTags = "#DefaultTag"
if (project.hasProperty('cucumberTags')) {
logger.lifecycle("THIS IS MAAAAAAAAAAAAAAAAAAAAAARK")
cucumberTags = project.property('cucumberTags');
}
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
logger.lifecycle("Run cucumber tests by tag: " + cucumberTags)
args = [
// '--plugin', 'io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm',
'--tags', cucumberTags
]
logger.lifecycle("Cucumber args: " + args.join(" "))
}
}
}
Cucumber context configuration class
#Slf4j
#SpringBootTest
#Scope("cucumber.glue")
#CucumberContextConfiguration
#ContextConfiguration(loader = AnnotationConfigContextLoader.class,
classes = GeneralConfiguration.class)
public class CucumberContext {
}
gradle command ./gradlew cucumber -PcucumberTags=#MyTag\
so, the thing is:
when allure-cucumber7-jvm dependency is commented, tests are running both from Intellij UI and via gradle cli.
when dependency is uncommented and gradle project reloaded, i still can run the test via Intellij UI, but not via gradle task
> Configure project :
Run cucumber gradle task.
> Task :cucumber
THIS IS MAAAAAAAAAAAAAAAAAAAAAARK
Run cucumber tests by tag: #MyTag
Cucumber args: --tags #MyTag
0 Scenarios
0 Steps
0m1.683s
But why?
I didn't find much examples with allure-cucumber7-jvm,
no any specific instructions on allure github as well.
I also tried to add dependency 'io.qameta.allure', name: 'allure-cucumber-jvm', version: '2.7.0'
tests are running, but, obviously, while i'm adding the plugin, it fails because of incopatibility of those cucumber and allure versions
Related
I am creating serenity + gradle + cucumber6 test framework. Everything works fine but I get error when I want to send cucumber options from the command line:
gradle test -Dcucumber.options="--tags #SmokeTest"
I get error:
Task '.options=--tags #SmokeTest' not found in root project 'MySerenityRestStarter'.
In build.gradle file I have:
test {
testLogging.showStandardStreams = true
systemProperties System.getProperties()
systemProperty "cucumber.options", System.getProperty("cucumber.options")
}
Any advice?
I use Gradle 6.8.3
You can see complete build gradle file or checkout project here https://github.com/draganstanisavljevic/serenity-cucumber-restapi-starter
Please try this:
In build.gradle:
sourceCompatibility = 11
targetCompatibility = 11
test {
systemProperty "cucumber.filter.tags", System.getProperty("cucumber.filter.tags")
testLogging {
showStandardStreams = true
}
}
Here is how u pass the tags:
gradle test -Dcucumber.filter.tags="#SmokeTest"
I can build my JHipster gateway with gradle from the development machine, but when I give it to the Gitlab CI I get this error at the 'gradle-package' step:
92 $ ./gradlew bootJar -Pprod -x check --no-daemon
93 To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.4.1/userguide/gradle_daemon.html.
94 Daemon will be stopped at the end of the build stopping after processing
95 > Task :bootBuildInfo
96 > Task :nodeSetup SKIPPED
97 > Task :npmSetup SKIPPED
98 > Task :npmInstall UP-TO-DATE
99 > Task :webpack FAILED
100 FAILURE: Build failed with an exception.
101 * What went wrong:
102 Execution failed for task ':webpack'.
103 > A problem occurred starting process 'command 'npm''
This is the .gitlab-ci.yml
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .gradle/
stages:
- check
- build
- test
- analyze
- package
- release
- deploy
before_script:
- export NG_CLI_ANALYTICS="false"
- export GRADLE_USER_HOME=`pwd`/.gradle
- ./gradlew npm_install -PnodeInstall --no-daemon
nohttp:
stage: check
script:
- ./gradlew checkstyleNohttp --no-daemon
gradle-compile:
stage: build
script:
- ./gradlew compileJava -x check -PnodeInstall --no-daemon
artifacts:
paths:
- build/classes/
- build/generated/
expire_in: 1 day
gradle-test:
stage: test
script:
- ./gradlew test -PnodeInstall --no-daemon
artifacts:
reports:
junit: build/test-results/test/TEST-*.xml
paths:
- build/test-results/
- build/jacoco/
expire_in: 1 day
gradle-integration-test:
stage: test
script:
- ./gradlew integrationTest -PnodeInstall --no-daemon
artifacts:
reports:
junit: build/test-results/integrationTest/TEST-*.xml
paths:
- build/test-results/
- build/jacoco/
expire_in: 1 day
frontend-test:
stage: test
script:
- ./gradlew npm_run_test -PnodeInstall --no-daemon
artifacts:
reports:
junit: build/test-results/TESTS-results-jest.xml
paths:
- build/test-results/
- build/jacoco/
expire_in: 1 day
gradle-package:
stage: package
script:
- ./gradlew bootJar -Pprod -x check --no-daemon
artifacts:
paths:
- build/libs/*.jar
- build/classes
expire_in: 1 day
# Uncomment the following line to use gitlabs container registry. You need to adapt the REGISTRY_URL in case you are not using gitlab.com
docker-push:
stage: release
variables:
REGISTRY_URL: 10.1.10.58
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
dependencies:
- gradle-package
script:
- ./gradlew jib -Pprod -Djib.allowInsecureRegistries=true -Djib.to.image=$IMAGE_TAG -Djib.to.auth.username="gitlab-ci-token" -Djib.to.auth.password=$CI_BUILD_TOKEN
build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "https://repo.spring.io/plugins-release" }
}
dependencies {
//jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
}
}
plugins {
id "java"
id "maven-publish"
id "idea"
id "jacoco"
id "org.springframework.boot"
id "com.google.cloud.tools.jib"
id "com.gorylenko.gradle-git-properties"
id "com.github.node-gradle.node"
id "net.ltgt.apt-eclipse"
id "net.ltgt.apt-idea"
id "net.ltgt.apt"
id "org.liquibase.gradle"
id "org.sonarqube"
id "io.spring.nohttp"
//jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here
}
group = "com.rps.png"
version = "0.0.1-SNAPSHOT"
description = ""
sourceCompatibility=1.8
targetCompatibility=1.8
assert System.properties["java.specification.version"] == "1.8" || "11" || "12" || "13" || "14"
apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here
if (project.hasProperty("prod") || project.hasProperty("gae")) {
apply from: "gradle/profile_prod.gradle"
} else {
apply from: "gradle/profile_dev.gradle"
}
if (project.hasProperty("war")) {
apply from: "gradle/war.gradle"
}
if (project.hasProperty("gae")) {
apply plugin: 'maven'
apply plugin: 'org.springframework.boot.experimental.thin-launcher'
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}"
}
}
appengineStage.dependsOn thinResolve
}
if (project.hasProperty("zipkin")) {
apply from: "gradle/zipkin.gradle"
}
idea {
module {
excludeDirs += files("node_modules")
}
}
eclipse {
sourceSets {
main {
java {
srcDirs += ["build/generated/sources/annotationProcessor/java/main"]
}
}
}
}
defaultTasks "bootRun"
springBoot {
mainClassName = "com.rps.png.GatewayuApp"
}
test {
useJUnitPlatform()
exclude "**/*IT*", "**/*IntTest*"
testLogging {
events 'FAILED', 'SKIPPED'
}
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
task integrationTest(type: Test) {
useJUnitPlatform()
description = "Execute integration tests."
group = "verification"
include "**/*IT*", "**/*IntTest*"
testLogging {
events 'FAILED', 'SKIPPED'
}
if (project.hasProperty('testcontainers')) {
environment 'spring.profiles.active', 'testcontainers'
}
// uncomment if the tests reports are not generated
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
}
check.dependsOn integrationTest
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn test
}
task integrationTestReport(type: TestReport) {
destinationDir = file("$buildDir/reports/tests")
reportOn integrationTest
}
if (!project.hasProperty("runList")) {
project.ext.runList = "main"
}
project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml"
liquibase {
activities {
main {
driver "org.h2.Driver"
url "jdbc:h2:file:./build/h2db/db/gatewayu"
username "gatewayu"
password ""
changeLogFile "src/main/resources/config/liquibase/master.xml"
defaultSchemaName ""
logLevel "debug"
classpath "src/main/resources/"
}
diffLog {
driver "org.h2.Driver"
url "jdbc:h2:file:./build/h2db/db/gatewayu"
username "gatewayu"
password ""
changeLogFile project.ext.diffChangelogFile
referenceUrl "hibernate:spring:com.rps.png.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy"
defaultSchemaName ""
logLevel "debug"
classpath "$buildDir/classes/java/main"
}
}
runList = project.ext.runList
}
gitProperties {
failOnNoGitDirectory = false
keys = ["git.branch", "git.commit.id.abbrev", "git.commit.id.describe"]
}
checkstyle {
toolVersion '${checkstyle_version}'
configFile file("checkstyle.xml")
checkstyleTest.enabled = false
}
nohttp {
source.include "build.gradle", "README.md"
}
configurations {
providedRuntime
implementation.exclude module: "spring-boot-starter-tomcat"
all {
resolutionStrategy {
// Inherited version from Spring Boot can't be used because of regressions:
// To be removed as soon as spring-boot use the same version
force 'org.liquibase:liquibase-core:3.9.0'
}
}
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
//jhipster-needle-gradle-repositories - JHipster will add additional repositories
}
dependencies {
// import JHipster dependencies BOM
if (!project.hasProperty("gae")) {
implementation platform("io.github.jhipster:jhipster-dependencies:${jhipster_dependencies_version}")
}
// Use ", version: jhipster_dependencies_version, changing: true" if you want
// to use a SNAPSHOT release instead of a stable release
implementation group: "io.github.jhipster", name: "jhipster-framework"
implementation "javax.annotation:javax.annotation-api"
implementation "org.springframework.boot:spring-boot-starter-cache"
implementation "io.dropwizard.metrics:metrics-core"
implementation "io.micrometer:micrometer-registry-prometheus"
implementation "net.logstash.logback:logstash-logback-encoder"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
implementation "com.fasterxml.jackson.module:jackson-module-jaxb-annotations"
implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
implementation "com.fasterxml.jackson.core:jackson-annotations"
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.module:jackson-module-afterburner"
implementation "org.apache.httpcomponents:httpclient"
implementation "javax.cache:cache-api"
implementation "org.hibernate:hibernate-core"
implementation "com.zaxxer:HikariCP"
implementation "commons-codec:commons-codec"
implementation "org.apache.commons:commons-lang3"
implementation "commons-io:commons-io"
implementation "javax.transaction:javax.transaction-api"
implementation "org.ehcache:ehcache"
implementation "org.hibernate:hibernate-jcache"
implementation "org.hibernate:hibernate-entitymanager"
implementation "org.hibernate.validator:hibernate-validator"
implementation "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:${liquibase_hibernate5_version}"
liquibaseRuntime sourceSets.main.compileClasspath
implementation "org.springframework.boot:spring-boot-loader-tools"
implementation "org.springframework.boot:spring-boot-starter-mail"
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-aop"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
testImplementation "org.testcontainers:mysql"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation ("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
implementation "org.springframework.boot:spring-boot-starter-undertow"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
implementation "org.zalando:problem-spring-web"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-zuul"
implementation "com.github.vladimir-bukhtoyarov:bucket4j-core"
implementation "com.github.vladimir-bukhtoyarov:bucket4j-jcache"
implementation "org.springframework.cloud:spring-cloud-starter"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-ribbon"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-hystrix"
implementation "org.springframework.retry:spring-retry"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
implementation "org.springframework.cloud:spring-cloud-starter-config"
implementation "org.springframework.cloud:spring-cloud-starter-security"
implementation "org.springframework.cloud:spring-cloud-starter-openfeign"
implementation "org.springframework.boot:spring-boot-starter-cloud-connectors"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-data"
implementation "org.springframework.security:spring-security-web"
implementation "org.springframework.security.oauth:spring-security-oauth2"
implementation "org.springframework.security:spring-security-jwt"
implementation "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
implementation ("io.springfox:springfox-swagger2") {
exclude module: "mapstruct"
}
implementation "io.springfox:springfox-bean-validators"
implementation "mysql:mysql-connector-java"
liquibaseRuntime "mysql:mysql-connector-java"
implementation "org.mapstruct:mapstruct:${mapstruct_version}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}"
annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernate_version}"
annotationProcessor "org.glassfish.jaxb:jaxb-runtime:${jaxb_runtime_version}"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}"
testImplementation ("org.springframework.boot:spring-boot-starter-test") {
exclude group: "org.junit.vintage", module: "junit-vintage-engine"
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.springframework.boot:spring-boot-test"
testImplementation "com.tngtech.archunit:archunit-junit5-api:${archunit_junit5_version}"
testRuntimeOnly "com.tngtech.archunit:archunit-junit5-engine:${archunit_junit5_version}"
testImplementation "com.h2database:h2"
liquibaseRuntime "com.h2database:h2"
//jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}
if (project.hasProperty("gae")) {
task createPom {
def basePath = 'build/resources/main/META-INF/maven'
doLast {
pom {
withXml(dependencyManagement.pomConfigurer)
}.writeTo("${basePath}/${project.group}/${project.name}/pom.xml")
}
}
bootJar.dependsOn = [createPom]
}
task cleanResources(type: Delete) {
delete "build/resources"
}
wrapper {
gradleVersion = "6.4.1"
}
if (project.hasProperty("nodeInstall")) {
node {
version = "${node_version}"
npmVersion = "${npm_version}"
yarnVersion = "${yarn_version}"
download = true
}
}
compileJava.dependsOn processResources
processResources.dependsOn bootBuildInfo
This is a JHipster gateway 6.9 with only minor changes from the default. In particular, I didnt' touch the 'gradle-package' which is failing on the Gitlab Runner.
What's the [Docker] image you run your job on? I don't see any image: specifications in your .gitlab-ci.yml. Make sure it has npm installed or make sure that your Gradle scripts contains instructions or tasks for installing it. You should probably set nodeInstall property before running the build:
if (project.hasProperty("nodeInstall")) {
node {
version = "${node_version}"
npmVersion = "${npm_version}"
yarnVersion = "${yarn_version}"
download = true
}
}
I have been trying to configure spock in the gradle project. So with the following configuration, it works out.
apply plugin: 'groovy'
My test cases are in the folder src/test/groovy. This works fine.I am able to run the test case.
However , I want to separate the integration tests into a separate folder structure - src/itest/groovy.
For this I added the following:
sourceSets {
itest {
srcDir file('src/itest/groovy')
}
resourceDir ..
compileClassPath ..
}
configurations {
itestCompile.extendsfrom testCompile
}
I am not able to copy the entire code here because of org restrictions. But I did try what all variations I could get online and it did not work!!
I always got the error:
The task compileItestGroovy was not found in the project.
I did some research and this task is added by the groovy plugin by default. Still the task could not be found and my build is in limbo. It would be great if you could help me up with this.
P.S This project also has other plugins such as java as the source code is in java.
Command to run - ./gradlew clean build
Gradle version - 2.2.1
I tried similar set up on my home pc with gradle version 3.5 and it works fine.
Given the following build.gradle file:
apply plugin: 'groovy'
repositories {
jcenter()
}
sourceSets {
integration {
groovy {
compileClasspath += main.output
runtimeClasspath += main.output
srcDirs = ['src/integration/groovy']
}
resources.srcDir file('src/integration/resources')
}
}
configurations {
// By default, integration tests have the same dependencies as standard tests
integrationCompile.extendsFrom testCompile
integrationRuntime.extendsFrom testRuntime
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.12'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
// This is only available for the integration tests
integrationCompile 'com.github.ben-manes.caffeine:caffeine:2.5.5'
}
tasks.create('integrationTest', Test) {
dependsOn 'compileIntegrationGroovy'
group = 'Verification'
description = 'Runs the integration tests'
// GRADLE 2.2
testClassesDir = sourceSets.integration.output.classesDir
// GRADLE 3.5
// testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
}
tasks.findByName('check').dependsOn 'integrationTest'
You should be able to stick integration tests inside src/integration/groovy and ./gradlew check will run both the standard tests, AND the integration tests
Hy i have written a java Library an I want to use it in the Gradle script. What I have done:
Added the repository:
repositories {
maven {
url "../Projectname/maven_repo"
}
}
Added the Dependency:
dependencies {
classpath group: 'my.group.id', name: 'Projectname', version: '0.0.1-SNAPSHOT'
}
And now i want to use the Library in a Task:
task myTask () {
def file = file("${buildDir}/ws/.metadata/.log")
def htmlParser = new my.package.Projectname()
}
Now I always get the exception on the Buildserver that he isn’t able to find the class.
Thx for the Help.
I have written a tool OwnerFinder that does some annotation processing on some jars of an application. I need to expose this tool on TeamCity so have written a gradle script which performs following tasks
Extract the application zip file
Copy the application jars to a location build/appJars
compile tool OwnerFinder (keep the appJars in the classpath)
create jar of OwnerFinder
Run OwnerFinder(keep the appJars in the classpath)
(I need to keep the app jars in the class path because the annotation for which processing needs to be done is in those jars)
But somehow the order of the task is not guaranteed even after using dependsOn and mustRunAfter. The script fails either at
compilation task (where its not able to find the annotation in the dependencies)
or
run task where its not able to find the class OwnerFinder
but after 2nd or 3rd try it runs sucessfully. This makes me think that the gradle tasks are not executing as per order.
Following is my gradle script:-
apply from: 'http://some-gradle-util-script'
apply plugin: 'java'
def confs = ["someApplicationConf"]
confs.each { configurations.create it }
configurations { sources }
configureDownload('ivy', 'ivy-integrated')
dependencies {
def someApplicationVersion = '1.12.0.+'
someApplicationConf "com.soft:someApplication-sync:${someApplicationVersion}#zip"
compile 'com.google.guava:guava:16.0.1',
'com.google.code.gson:gson:2.2.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
task unzip(type: Copy, dependsOn: clean) {
from zipTree(configurations.someApplicationConf.singleFile)
into "$buildDir/unzipped"
}
task copyJar(type: Copy, dependsOn: unzip) {
from "$buildDir/unzipped/modules"
into "$buildDir/op"
}
copyJar.mustRunAfter unzip
task compileOwnerFinder(type: JavaCompile, dependsOn: copyJar) {
FileCollection f = files(fileTree(dir: 'build/op', include: '*.jar').files, configurations.compile.files)
source = fileTree(dir: 'src', include: '**/*.java')
classpath = f
destinationDir = new File("$buildDir/classes/main")
}
compileOwnerFinder.mustRunAfter copyJar
task jarOwnerFinder(type: Jar, dependsOn: compileOwnerFinder) {
from files(sourceSets.main.output.classesDir)
}
task runOwnerFinder(type: Exec, dependsOn: jarR) {
def classpath = fileTree(dir: 'build/op', include: '*.jar').files + configurations.compile.files +
fileTree(dir: 'build/libs', include: '*.jar').files
commandLine "java", "-classpath", classpath.join(File.pathSeparator), "OwnerFinder"
}
runOwnerFinder.mustRunAfter jarOwnerFinder