title: Execute Cucumber Integration Tests with Spring Boot server running from Gradle plugin on Jenkins or any other CI server
body: <p>I have a spring boot micro-services project built with Gradle.</p>
  
  <p>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 <strong><code>gradle build</code></strong>. </p>
  
  <p>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.</p>
  
  <p><strong>This is exactly what I want through gradle build:</strong> </p>
  
  <p><strong>How the cucumber integration tests get executed on a running spring boot embedded server by gradle.build ??</strong> </p>
  
  <p><strong>Current behavior is</strong>: when the <strong><code>gradle.build</code></strong> is called on CI server then the cucumber integration tests are just getting called with no target spring boot server. </p>
  
  <p><strong>Expected behavior:</strong> After <strong><code>gradle.build</code></strong> 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. </p>
  
  <p><strong>NOTE: I have created a special <code>cucumber-test</code> profile for it in the project and have its own configuration file</strong></p>
  
  <p>My <code>gradle.build</code> looks like:</p>
  
  <pre><code>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"
      }
  }
  </code></pre>
  
  <p>My <strong><code>project structure</code></strong> looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/pz96h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pz96h.png" alt="Project Structure"></a></p>
  
  <p><strong><code>StepsDefinitionAnnotations</code></strong></p>
  
  <p><a href="https://i.stack.imgur.com/xftv1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xftv1.png" alt="StepsDefinitionAnnotations"></a></p>
  
  <p><strong><code>CucumberTest</code></strong>
  <a href="https://i.stack.imgur.com/1dl2U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1dl2U.png" alt="CucumberTest"></a></p>
  
  <p>Thanks very much !!</p>