Gradle downloads pom.xml but not the .jar file for Cucumber - gradle

I'm trying to get Cucumber running from Gradle. When I try to execute Cucumber tests I get
Error: Could not find or load main class cucumber.api.cli.Main
Gradle downloaded the cucumber-jvm-1.1.3.pom file but none of the cucumber .jar files. Here is my build.gradle:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'info.cukes:cucumber-jvm:1.1.3'
}
configurations {
cucumberRuntime {
extendsFrom testRuntime
}
}
task runCucTests(type: JavaExec) {
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['-f', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources', '--tags #complete', ' --format junit:target/reports/cucumber-junit-report/allcukes.xml', '--format pretty', '--format html:target/reports/cucumber-html-report']
}
I've tried changing the dependency to runtime and changing the cucumberRuntime to extend from runtime but the result is the same.
Why isn't gradle recognizing that it needs to download the cucumber .jar files?
Thanks.

cucumber-jvm is the parent group
cucumber.api.cli.Main requires cucumber-core
Use below:
dependencies {
compile "info.cukes:cucumber-core:1.1.3"
}
This will download the required jar.

Related

Spock test in gradle could not be configured in a separate sourceSet

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

multiple testng test listeners running using gradle test command

I have 2 custom listeners implementing ITestListener, ISuiteListener, IInvokedMethodListener . when I run the command from gradle as gradle clean --test testname . it runs both listeners though I have only one class defined in the #Listeners annotation in test. Its a gradle project but when I run the test in intellij as testng test it runs with only 1 listener as expected. Can you please tell how to make it run with only 1 listener using gradle command
my build.gradle below and testng version I am using is 6.9.4 and I tried 6.9.10 too
ext {
unitTestingMinHeapSize = "512m"
}
// Apply the java plugin to add support for Java
apply plugin: 'java'
// Apply the application plugin to add support for building an application
apply plugin: 'application'
// Apply the eclipse plugin to add support for building on eclipse
apply plugin: 'eclipse'
// Apply the idea plugin to add support for building on IDEA
apply plugin: 'idea'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
mavenLocal()
}
// In this section you declare the dependencies for your production and test code
dependencies {
compile project(':oos')
testCompile project(':oos')
compile "commons-pool:commons-pool:$apacheCommonsPool1Version"
compile "org.apache.commons:commons-lang3:$apacheCommonsLangVersion"
compile "org.apache.commons:commons-pool2:$apacheCommonsPool2Version"
compile "com.rabbitmq:amqp-client:$rabbitMQClientVersion"
compile "redis.clients:jedis:$jedisVersion"
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
compile "org.apache.httpcomponents:httpmime:$httpmimeversion"
compile "io.rest-assured:rest-assured:$restAssuredVersion"
compile "org.hamcrest:hamcrest-all:$hamcrestVersion"
compile "org.postgresql:postgresql:$postgresqlversion"
compile "com.googlecode.json-simple:json-simple:1.1.1"
compile "com.codepine.api:testrail-api-java-client:1.0.2"
testCompile "org.mockito:mockito-all:$mockitoVersion"
testCompile "org.springframework:spring-test:$springVersion"
compile ("org.testng:testng:$testngVersion") {
exclude group: "junit", module: "junit"
}
testCompile "org.apache.commons:commons-pool2:$apacheCommonsPool2Version"
}
test {
for (String key : System.getProperties().keySet()) {
systemProperty key, System.properties["$key"]
}
jvmArgs "-XX:-UseSplitVerifier"
systemProperty "runId", findProperty("runId")
useTestNG { useDefaultListeners = true }
beforeTest { descriptor ->
logger.lifecycle("Running: " + descriptor)
}
minHeapSize = "$unitTestingMinHeapSize"
jvmArgs '-XX:+UseConcMarkSweepGC', '-XX:+CMSIncrementalMode' //,'-XX:+PrintGCDetails','-XX:+PrintGCTimeStamps'
if (System.getProperty("test.profile", "false").equals("true")) {
jvmArgs "-noverify", "-agentpath:${profilerDir}/lib/deployed/jdk16/mac/libprofilerinterface.jnilib=${profilerDir}/lib,5140,0"
}
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
// logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
if (event.destination == TestOutputEvent.Destination.StdErr) {
logger.error(" ERROR: " + event.message.trim())
}
}
}

Add additional source set to Gretty classpath

My project contains a jar and a war module. The jar module contains to source sets main and generated.
My jar module gradle.build defines the source sets as listed below:
sourceSets {
generated
main {
compileClasspath += sourceSets.generated.output // adds the sourceSet to the compileClassPath
runtimeClasspath += sourceSets.generated.output // adds the sourceSet to the runtimeClasspath
}
}
and places the output of both source sets into the jar.
jar {
from sourceSets.generated.output
from sourceSets.main.output
}
Within my war module I'd like to use Gretty to run it within the build. The build.gradle file looks like this.
apply plugin: 'war'
apply from: "${rootDir}/gradle/gretty.gradle"
gretty {
// supported values:
// 'jetty7', 'jetty8', 'jetty9', 'tomcat7', 'tomcat8'
servletContainer = 'tomcat8'
httpPort = 8081
contextPath = '/wbc'
realm 'wbc-realm'
realmConfigFile 'tomcat-users.xml'
}
dependencies {
compile project(':interfaces')
compile "org.atmosphere:atmosphere-runtime:${atmosphereVersion}"
compile "org.springframework:spring-web:${springVersion}"
compile "javax.servlet:javax.servlet-api:${servletVersion}"
runtime "org.slf4j:slf4j-log4j12:${slf4jVersion}"
runtime "log4j:log4j:1.2.17"
}
Whenever I start Gretty using gradle --daemon clean appRun Gretty fails to start up Tomcat due to a ClassNotFoundException. That class is located in the generated source set of my jar module. How can I tell gretty to add it to the classpath?
Try adding the output directories of generated to gretty classPath:
gretty {
...
sourceSets.generated.output.each { classPath it }
}

Building a fully executable Spring Boot 1.3 war from a Gradle multi project build

I'm trying to build a fully executable WAR using Spring Boot 1.3 as per https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html. If I build a single Gradle project, it all works fine, but I havea multi project build, where I have a "root" project and then several projects underneath it, and I cannot get it to build anything but a standard, "fat" WAR file, without the providedRuntime of Jetty and without the scripts to make it run.
Does anyone know how to do this?
In my root project, I have the following (abridged):
buildscript {
repositories {
mavenCentral()
}
ext {
springBootVersion = '1.3.0.RELEASE'
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
}
}
allprojects {
//Put instructions for all projects
repositories {
mavenCentral() // jcenter is missing spring-orm.4.1.6.RELEASE jar file so try mavenCentral first
jcenter {
url "http://jcenter.bintray.com/"
}
maven { url 'http://repo.opensourceagility.com/release' }
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'spring-boot'
}
and then in the subproject which is a web project, and which I'm trying to build, I have:
apply plugin: 'war'
dependencies {
// Include related projects
compile project(':project-model')
compile project(':project-dynamoDB')
// Core Spring Boot - note version is set in main build.gradle file
compile 'org.springframework.boot:spring-boot-starter-web'
// Remove Tomcat (included in -web) and include Jetty instead
providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'
// Other Spring modules
compile 'org.springframework.boot:spring-boot-starter-social-facebook'
compile 'org.springframework.boot:spring-boot-starter-social-linkedin'
compile 'org.springframework.social:spring-social-google:1.0.0.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework:spring-context'
compile 'org.springframework:spring-context-support'
}
configurations {
providedRuntime.exclude group: 'org.springframework.boot', module:'spring-boot-starter-tomcat'
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' // exclude when using log4j
}
springBoot {
mainClass = 'rs.web.Weblication'
executable = true
}
bootRun {
addResources = true
}
processResources {
// exclude resources if they look like they're profile dependent but don't match the current env/profile
eachFile { d ->
if(d.name.endsWith('.xml') || d.name.endsWith('.yaml') || d.name.endsWith('.properties')) {
//def fname = d.name.replaceFirst(~/\.[^\.]+$/, '')
//if(fname.indexOf("-") > -1 && ! fname.endsWith("-" + environment)) {
// d.exclude()
//} else {
// replace #variables# listed below in properties/config files
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
activeProfiles: environment
])
//}
}
}
}
war {
baseName = 'project-web'
version = '1.0.0'
manifest {
attributes 'Implementation-Title': baseName,
'Implementation-Version': version
}
webXml = file('src/main/resources/web.xml')
// rename the war task which has profiles appended from warName-profile,profile2.war
// to warName-profile.profile2.war
classifier = environment.replaceAll(',','-')
}
but when I build it (./gradlew build, or ./gradlew subprojectname:build), all is well and a working WAR is created, but not an executable one.
With a single project, I have it working fine.
Ah ha, right well I build a test multi-project build and it worked OK, so it was clearly the configuration above.
I worked through a process of elimination and it turns out that the problematic area was the line
classifier = environment.replaceAll(',','-')
which is intended to rename files with environment variables as part of the name. This process seems to get in the way of the script addition; perhaps it could be applied afterwards if it's really necessary.

How to generate multiple jar files with gradle's java plugin

I have a multi-project gradle build using the java plugin setup as follows:
myProj/
settings.gradle
build.gradle
util/
build.gradle
In my util project, I would like to generate 2 jars... one for packageA and one for packageB. I'm a noob with gradle so any help here would be much appreciated. Here are my settings and gradle files:
myProj/settings.gradle
include 'util'
myProj/build.gradle
subprojects {
apply plugin: 'java'
repositories {
maven {
url "http://mymavenurl"
}
}
sourceSets {
main {
java {
srcDir 'src/java'
}
}
}
}
myProj/util/build.gradle
dependencies {
.
.
.
}
jar {
baseName = 'packageA'
includes = ['com/mycomp/packageA']
}
task packageBJar(type: Jar) {
dependsOn classes
includes = ['com/mycomp/packageB']
baseName = 'packageB'
}
When I try to build my project here is the output:
:util:compileJava
:util:processResources UP-TO-DATE
:util:classes
:util:jar
:util:assemble
:util:compileTestJava UP-TO-DATE
:util:processTestResources UP-TO-DATE
:util:testClasses UP-TO-DATE
:util:test
:util:check
:util:build
I would hope to see :util:packageBJar after classes, but I'm not having any luck.
One way is to declare packageBJar as an artifact of, say, the archives configuration:
artifacts {
archives packageBJar
}
Now gradle assemble, and therefore also gradle build, will produce packageBJar.

Resources