Karate Gatling with gradle build is not working [duplicate] - gradle

This question already has answers here:
How to run Karate and Gatling with Gradle build system
(2 answers)
Closed 1 year ago.
I am trying to run gatling with karate in gradle build and getting below error,
/smoketests/SmokeTestRunner.java:19: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
^
/smoketests/SmokeTestRunner.java:21: error: package com.intuit.karate.junit4 does not exist
import com.intuit.karate.junit4.Karate;
^
/smoketests/SmokeTestRunner.java:30: error: cannot find symbol
#RunWith(Karate.class)
^
symbol: class RunWith
/wskadmin/WskAdminRunner.java:19: error: package org.junit does not exist
import org.junit.Test;
^
/wskadmin/WskAdminRunner.java:20: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
^
/wskadmin/WskAdminRunner.java:22: error: package com.intuit.karate.junit4 does not exist
import com.intuit.karate.junit4.Karate;
and exception as
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileGatlingScala'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
For more information,
below is my build.gradle file,
plugins {
id "com.github.lkishalmi.gatling" version "0.7.3"
}
apply plugin: 'java'
apply plugin: 'maven'
group = 'karate-gatling'
version = '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
maven { url "http://repo.maven.apache.org/maven2" }
}
sourceSets {
gatling {
scala.srcDirs = ['src/test/java']
}
test {
java
{
srcDir file('src/test/java')
// exclude '**/*.java'
}
resources
{
srcDir file('src/test/java')
// exclude '**/*.java'
}
}
}
dependencies {
compile group: 'com.jcraft', name: 'jsch', version:'0.1.53'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.10.0'
compile group: 'com.intuit.karate', name: 'karate-netty', version:'0.8.0.1'
testCompile group: 'net.masterthought', name: 'cucumber-reporting', version:'3.8.0'
testCompile group: 'com.intuit.karate', name: 'karate-apache', version:'0.8.0.1'
testCompile group: 'com.intuit.karate', name: 'karate-junit4', version:'0.8.0.1'
testCompile group: 'com.intuit.karate', name: 'karate-gatling', version:'0.8.0.1'
gatling 'com.intuit.karate:karate-gatling:0.8.0.1'
gatling 'com.google.code.gson:gson:2.8.0'
gatling 'org.apache.httpcomponents:httpclient:4.3.2'
gatlingCompile 'org.apache.commons:commons-lang3:3.4'
gatlingRuntime 'cglib:cglib-nodep:3.2.0'
}
gatling {
sourceRoot = 'src/test/java'
toolVersion = '2.3.1'
}
to run my simulation class i am using below command,
./gradlew clean gatlingRun-mypackage.LoadTest
Below is my LoadTest.scala file
class LoadTest extends Simulation {
before{
println("Simulation is about to start!")
}
val createActionTest = scenario("smoke").exec(karateFeature("classpath:path/myfeature.feature"))
setUp(createActionTest.inject(rampUsers(5) over (5 seconds))
).maxDuration(1 minutes).assertions(global.responseTime.mean.lt(1100))
after {
println("Simulation is finished!")
}
}
And below is my runner file
import org.junit.runner.RunWith;
import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions;
#RunWith(Karate.class)
#CucumberOptions(tags = {"~#ignore","~#driver","~#reliability","~#resiliency","~#concurrent","~#wskfunctions"})
public class SmokeTestRunner {
}
Any help on this is really appriciated

You need to add a testCompile dependency on JUnit, such as:
testCompile 'junit:junit:4.12'
gradle karate karate-gatling junit gradle-gatling-plugin

Related

The import cucumber cannot be resolved in Runner Class for Gradle Project

I don't whats wrong with my Gradle Dependencies but when I try to import import cucumber.api.junit.Cucumber; then I get error The import cucumber cannot be resolved
Below is my Gradle file:
apply plugin: 'java'
version = '1.0-SNAPSHOT'
dependencies {
compile group: 'info.cukes', name: 'cucumber-java', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
compile group: 'info.cukes', name: 'cucumber-core', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.5'
compile group: 'info.cukes', name: 'cucumber-guice', version: '1.2.5'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
repositories {
mavenCentral()
}
My Runner Class is:
package Runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
Cucumber.options(
features = "\\src\\test\\java\\Feature",
glue = {"\\src\\main\\java\\Steps\\"},
tags = {"#ignored"},
format = {"json:target/cucumber/wikipedia.json","html:target/cucumber/wikipedia.html","pretty"}
)
public class RunnerMain {
}
When I comment #RunWith, CucumberOptions and remove the imports, then run command gradle build then I don't see any error and all goes well.
I don't know what wrong I am doing here.
Replace Cucumber.options with #CucumberOptions and try once

Execute Cucumber Integration Tests with Spring Boot server running from Gradle plugin on Jenkins or any other CI server

I have a spring boot micro-services project built with Gradle.
I want to execute my cucumber integration tests on Jenkins or CI server just after code check-in. The build job on CI server gets triggered automatically after every code check-in. This job calls my gradle build.
I am able to execute the cucumber test cases as normal JUnit test case from my STS or eclipse and the embedded tomcat server gets started and after the cucumber test cases get executed on it, the server is stopped.
This is exactly what I want through gradle build:
How the cucumber integration tests get executed on a running spring boot embedded server by gradle.build ??
Current behavior is: when the gradle.build is called on CI server then the cucumber integration tests are just getting called with no target spring boot server.
Expected behavior: After gradle.build is called on CI server, the cucumber tests should get executed on the running spring boot embedded server and should get stop by itself after the cucumber test cases are executed.
NOTE: I have created a special cucumber-test profile for it in the project and have its own configuration file
My gradle.build looks like:
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
manifest {
attributes 'Main-Class': 'com.pa.omas.Main'
}
baseName = 'omas'
version = ''
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "http://smartbearsoftware.com/repository/maven2" }
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
cucumberRuntime {
extendsFrom testRuntime
}
}
task copyScripts(type: Copy) {
from("scripts")
into("build/libs")
}
task copyReports(type: Copy) {
from("reports")
into("build/libs/reports")
}
task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}
check.dependsOn integrationTest
integrationTest.mustRunAfter test
tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
}
bootRun {
args = ["--spring.profiles.active=cucumber-test"]
}
task cucumber(){
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['-p', 'pretty', '--monochrome', '-p', 'html:reports/cucumber/cucumber-html-reports', '-p', 'junit:reports/cucumber-junit/cucumber-junit-report.xml',
'-p', 'html:reports/cucumber', '--glue', 'src/integration-test/java/com/pa/omas/cucumber', 'src/integration-test/resources']
}
copyReports
}
}
build {
dependsOn copyScripts
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-starter-stream-kafka')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.projectlombok:lombok')
compile('org.springframework.boot:spring-boot-starter-web')
compile('ch.qos.logback:logback-classic')
compile('org.mariadb.jdbc:mariadb-java-client:1.5.4')
compile('org.hibernate:hibernate-java8')
compile 'com.puppycrawl.tools:checkstyle:8.3'
compile group: 'net.masterthought', name: 'cucumber-reporting', version: '3.11.0'
compile group: 'net.masterthought', name: 'maven-cucumber-reporting', version: '3.11.0'
compile group: 'com.zaxxer', name: 'HikariCP', version: '2.6.3'
compile('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.7.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
testCompile('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-all', version: '2.0.2-beta'
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
integrationTestCompile('com.h2database:h2')
integrationTestCompile('org.springframework.boot:spring-boot-starter-test')
integrationTestCompile 'info.cukes:cucumber-java:1.2.5'
integrationTestCompile 'junit:junit:4.12'
integrationTestCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-java', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-core', version: '1.2.5'
integrationTestCompile group: 'info.cukes', name: 'cucumber-html', version: '0.2.6'
integrationTestCompile group: 'info.cukes', name: 'cucumber-jvm-deps', version: '1.0.5'
integrationTestCompile group: 'info.cukes', name: 'gherkin', version: '2.12.2'
integrationTestCompile group: 'io.cucumber', name: 'gherkin', version: '5.0.0'
integrationTestCompile group: 'info.cukes', name: 'cucumber-java8', version: '1.2.5'
integrationTestCompile group: 'org.webjars.npm', name: 'gherkin', version: '4.1.3'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR3"
}
}
My project structure looks like:
StepsDefinitionAnnotations
CucumberTest
Thanks very much !!
So finally, I found the solution to this issue.
The cucumber cli main class was unable to find the testRuntime in which the stepsDefinition file was located. Therefore, it was simply calling the cucumber test cases but not executing them.
All I did is included the sourceSets for main & test in the gradle file, linke below:
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
}
test {
java {
srcDirs = ["src/test/"]
}
}
}
And it worked fine for me.
Thanks Anyways. Hope this will help others as well !!

gradle - including compiled classes to testCompile to avoid NoClassDefFoundError

I am trying to include compiled classes (from the project3) to run junit tests.
Here is a brief project structure.
project1
build.gradle
project2
build.gradle
project3
src/main/java/***.java
src/test/java/***JunitTestClasses
build.gradle - I am running this.
Here is the build.gradle from project3.
apply plugin: 'java'
apply plugin: "jacoco"
apply plugin: 'maven'
apply plugin: 'com.github.jacobono.jaxb'
apply plugin: "io.spring.dependency-management"
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
repositories {
maven
{
// omitted.
}
}
dependencies
{
classpath 'com.github.jacobono:gradle-jaxb-plugin:' + GRADLE_JAXB_PLUGIN_VERSION
classpath 'io.spring.gradle:dependency-management-plugin:' + GRADLE_DEP_MGMT_PLUGIN_VERSION
}
}
dependencies
{
compile project(':project1')
compile project(':project2')
compile project(':project3')
compile group: 'org.apache.ant', name: 'ant', version: ANT_VERSION
jaxb group: 'com.sun.xml.bind', name: 'jaxb-xjc', version: JAXB_VERSION
jaxb group: 'com.sun.xml.bind', name: 'jaxb-impl', version: JAXB_VERSION
jaxb group: 'com.sun.xml.bind', name: 'jaxb-core', version: JAXB_VERSION
xmlbeans 'org.apache.xmlbeans:xmlbeans:2.5.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
runtime files('build/classes/main')
}
configurations {
repobootstrap
xmlbeans
}
sourceSets {
generated {
java {
srcDir file("${buildDir}/generated")
}
}
testGenerated {
compileClasspath += sourceSets.main.runtimeClasspath
java {
srcDir file("${buildDir}/generated")
}
}
main {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
test {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
}
test
{
systemProperties 'basedir': projectDir
systemProperties 'testdir': "${projectDir}/src/test"
systemProperties 'resourcedir': "${projectDir}/src/test/resources"
systemProperties 'TARGET': "${buildDir}/tmp"
systemProperties 'tmp.dir': "${buildDir}/tmp"
}
Some tasks which generate classes from XSD are omitted..
When I do 'gradle build', it successfully generates classes from XML and compiles. But when junit tests run, it throws 'java.lang.NoClassDefFoundError' for classes that belong to project3 and 'java.lang.ClassNotFoundException: schemaorg_apache_xmlbeans.system.sE2A73A83DA959459556520519D4CA82A.TypeSystemHolder'. Generated artifacts for xmlbeans are located under generated\schemaorg_apache_xmlbeans3 and compiled classes are located under project3/build/main
I'd appreciated if somebody has any clue.

slf4j LoggerFactory class definition not found with Gradle

I'm trying to build and run a Spark webserver that uses slf4j logging in IntelliJ. It builds fine (also in IntelliJ) on the computer that was used to originally add logging, but not on my machine.
Here's the full build.gradle file (see project(':webserver') for the part that uses the logger:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.avast.gradle:docker-compose-gradle-plugin:0.3.27"
}
}
subprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
apply plugin: "java"
apply plugin: "idea"
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "findbugs"
apply plugin: "application"
apply plugin: "com.avast.gradle.docker-compose"
checkstyle {
configFile = "../config/checkstyle/checkstyle.xml" as File
toolVersion = "6.0"
}
}
project(':webserver') {
mainClassName = "org.passport.webserver.WebServer"
dependencies {
compile project(':core')
compile "com.sparkjava:spark-core:2.6.0"
testCompile 'junit:junit:4.12'
compile group: 'org.json', name: 'json', version: '20090211'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.1'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':customsUI') {
mainClassName = "org.passport.customsui.CustomsUI"
dependencies {
compile project(':core')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':handlerUI') {
mainClassName = "org.passport.handlerui.HandlerUI"
dependencies {
compile project(':core')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':core') {
mainClassName = "org.passport.core.PassPortChaincode"
dependencies {
compile 'io.grpc:grpc-all:0.13.2'
compile 'commons-cli:commons-cli:1.3.1'
compile 'org.glassfish:javax.json:1.1.0-M1'
compile files('lib/shim-client-1.0.jar')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
Here's the code that uses the logger:
package org.passport.webserver;
import org.passport.webserver.endpoints.ContainerClaimDao;
import org.passport.webserver.endpoints.PackageClaimDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.path;
import static spark.Spark.post;
/**
* The server matches requests (routs) and calls the appropriate endpoints.
*/
public final class Server {
private static Logger logger = LoggerFactory.getLogger(Server.class);
private static ContainerClaimDao containers = new ContainerClaimDao();
private static PackageClaimDao packages = new PackageClaimDao();
private Server() {
}
/**
* Starts the router.
* #param args run arguments
*/
public static void main(String[] args) {
path("/containers/:container-id", () -> {
before("/*", (q, a) -> logger.info("Received api call: " + q.url() + "."));
post("", (request, response) -> containers.add(request, response));
get("/container-claims", (request, response) -> containers.get(request, response));
get("/package-claims", (request, response) -> packages.get(request, response));
});
}
}
And here's the error I get:
"C:\Program Files\Java\jdk1.8.0_91\bin\java" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;C:\Users\lover\repositories\passport\webserver\build\classes\main;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.passport.webserver.Server
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.passport.webserver.Server.<clinit>(Server.java:18)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
I've looked at several questions on StackOverflow, but none seem to solve the problem:
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory - I'm building with gradle, don't think I should have to download/ put some jar in my classpath
ClassNotFoundException: org.slf4j.LoggerFactory - Same as above
NoClassDefFoundError: org/slf4j/Logger - Again jar stuff
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory - I'm not sure whether "fat jars" / ShadowJar apply, and not sure how to modify my build file to use them
NoClassDefFoundError: org/slf4j/LoggerFactory while creating a runnable *.jar with gradle - I've tried refreshing gradle several times, restarting IntelliJ, and even restarting my restarting my computer
Gradle Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory - See below
I've tried the following dependencies:
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.1'
compile 'org.slf4j:slf4j-api:1.7.24' and compile 'org.slf4j:slf4j-simple:1.7.24'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
None of this seems to make a difference. Any ideas?
If you're using Gradle add these 2 lines to your build.gradle dependencies to use Spark 2.6.0
compile "com.sparkjava:spark-core:2.6.0"
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
I ended up deleting my Gradle cache (.gradle folder) and re-downloading everything, which solved the problem.

WebApplicationInitializer is not launched on jetty+selenium

i am trying to run selenium test on jetty using gradle and my gradle configuration is as follows:
gradle.build:
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
apply plugin: 'findbugs'
//apply from:'http://github.com/breskeby/gradleplugins/raw/master/emmaPlugin/emma.gradle'
apply from: 'emma.gradle'
apply plugin: 'jetty'
sourceCompatibility = 1.7
version = ''
sourceSets {
selenium
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0.6'
}
}
repositories {
mavenCentral()
mavenRepo url: 'http://repository.primefaces.org'
mavenRepo url: 'http://repository.jboss.org/nexus/content/groups/public'
mavenRepo url: 'http://repository.jboss.org/maven2'
mavenRepo url: 'http://maven.springframework.org/release'
mavenRepo url: 'http://repo1.maven.org/maven2'
mavenRepo url: 'http://git.solutionstream.com/nexus/content/repositories/thirdparty'
}
dependencies {
//JSF
compile group: 'com.sun.faces', name: 'jsf-api', version: '2.1.22'
compile group: 'com.sun.faces', name: 'jsf-impl', version: '2.1.22'
compile 'org.ocpsoft.rewrite:rewrite-servlet:2.0.3.Final'
compile 'org.ocpsoft.rewrite:rewrite-config-prettyfaces:2.0.3.Final'
compile 'javax.el:el-api:2.2'
runtime 'org.glassfish.web:el-impl:2.2'
//Servlet
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
providedCompile group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: '1.0.0.Final'
compile 'taglibs:standard:1.1.2'
compile group: 'org.springframework', name: 'spring-web', version: '3.2.2.RELEASE'
//Omnifaces
compile 'org.omnifaces:omnifaces:1.5'
//Prime Faces
compile group: 'org.primefaces', name: 'primefaces', version: '4.0-SNAPSHOT'
compile 'org.primefaces.themes:bootstrap:1.0.10'
// DB
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.3.1.RELEASE'
compile group: 'org.springframework', name: 'spring-aspects', version: '3.2.2.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.9'
compile group: 'javax.inject', name: 'javax.inject', version: '1'
compile group: 'javax.enterprise', name: 'cdi-api', version: '1.0-SP4'
compile 'cglib:cglib-nodep:2.2.2'
//Hibernate / JPA
compile 'org.hibernate:hibernate-core:4.1.0.Final'
compile 'org.hibernate:hibernate-entitymanager:4.1.0.Final'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final'
//JSR-303
compile 'org.hibernate:hibernate-validator:4.3.1.Final'
// Spring Security
compile 'org.springframework.security:spring-security-core:3.1.4.RELEASE'
compile 'org.springframework.security:spring-security-web:3.1.4.RELEASE'
compile 'org.springframework.security:spring-security-config:3.1.4.RELEASE'
//Utility
compile 'com.google.guava:guava:14.0.1'
compile 'commons-lang:commons-lang:2.6'
compile 'org.apache.commons:commons-email:1.3.1'
compile 'com.typesafe:config:1.0.0'
compile 'joda-time:joda-time:2.2'
compile 'org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:1.8.3'
compile 'org.slf4j:slf4j-api:1.7.2'
compile 'org.slf4j:jcl-over-slf4j:1.7.2'
compile 'org.slf4j:slf4j-log4j12:1.7.2'
//Mustache Templates
compile 'com.github.jknack:handlebars:1.0.0'
//Projects
//compile project(":ExtraValidators")
////TESTING DEPENDENCIES
testCompile 'com.googlecode.jmockit:jmockit:1.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'com.h2database:h2:1.3.172'
//Spring Testing
testCompile 'org.springframework:spring-test:3.2.3.RELEASE'
/* Selenium */
seleniumCompile 'org.seleniumhq.selenium:selenium-java:2.33.0'
seleniumCompile 'junit:junit:4.11'
}
task wrapper(type: Wrapper){
gradleVersion = '1.5'
}
eclipse {
classpath {
downloadSources=true
plusConfigurations += configurations.seleniumCompile
}
}
task jettyDaemon(type: org.gradle.api.plugins.jetty.JettyRun) {
daemon = true
}
task selenium(type: Test, dependsOn: jettyDaemon) {
testClassesDir = sourceSets.selenium.output.classesDir
classpath = sourceSets.selenium.runtimeClasspath
}
WebApplicationInitializer:
package com.myapp.web.config;
import javax.faces.application.ProjectStage;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;
import com.myapp.data.config.SpringConfig;
import com.myapp.data.config.SpringJNDIDataConfig;
import com.myapp.data.config.SpringJNDIJPAConfig;
import com.myapp.data.config.SpringSecurityConfig;
import com.myapp.data.config.SpringWebConfig;
import com.myapp.utils.configuration.ConfigurationUtil;
public class WebappConfig implements WebApplicationInitializer {
protected final Logger logger = LoggerFactory.getLogger(getClass());
#Override
public void onStartup(final ServletContext servletContext) throws ServletException {
if(logger.isDebugEnabled()) {
logger.debug("Starting web context configuration");
}
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
// rootContext.getEnvironment().setActiveProfiles("production");
rootContext.register(SpringConfig.class, SpringSecurityConfig.class, SpringWebConfig.class, SpringJNDIDataConfig.class, SpringJNDIJPAConfig.class);
servletContext.addListener(RequestContextListener.class);
new ContextLoader(rootContext).initWebApplicationContext(servletContext);
addFilters(servletContext, rootContext.getEnvironment());
servletContext.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, ConfigurationUtil.config().getString("jsf.stage"));
servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", ConfigurationUtil.config().getString("jsf.refreshPeriod"));
}
private void addFilters(final ServletContext servletContext, final ConfigurableEnvironment configurableEnvironment) {
FilterRegistration.Dynamic securityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain"));
securityFilter.addMappingForUrlPatterns(null, false, "/*");
}
}
please advise how to make WebApplicationInitializer runs when running the selenium test on jetty.
WebApplicationInitializer requires a Servlet 3 container. However, Gradle's Jetty plugin is based on Jetty 6 which supports only Servlet 2.5.
You have a few options:
Configure your application with the web.xml file instead of WebApplicationInitializer
Use a newer Jetty version with Gradle. There are some workarounds in the comments of GRADLE-1956
Use an alternative container like Tomcat (gradle-tomcat-plugin)
Use an alternative plugin like gradle-cargo-plugin or arquillian-gradle-plugin. AFAIK there's a new gradle deployment plugin in the works that should be base on Arquillian.

Resources