Running an executable Jar before running Integration tests

Hi, We have a build that uses the application plugin to run an Embedded Jetty which we start using the “run” task. Our project is of type Jar. We want to start the Jetty process and then run tests against the instance and if tests complete, close down the process . This is something similar to the jetty plugin which needs the project to be a war.

I looked on the forums but did not see a solution that will work for this scenario.

Any suggestions will be very helpful

I figured out how to do this :

task executeLocalSmokeTest (type: Test, dependsOn:":uberJar") { //Note the colons for parent’s tasks.

def jettyProcess

useJUnit {

includeCategories = [‘TestCategories$SmokeTest’] as Set

}

testLogging {

exceptionFormat “full”

events “started”, “passed”, “skipped”, “failed”, “standardOut”, “standardError”

displayGranularity = 0

}

doFirst {

//Pass all system properties to the Test JVM

systemProperties = System.getProperties()

String command = System.getProperty(“java.home”) + “/bin/java”

jettyProcess = new ProcessBuilder(command ,

“-jar” , “-D@environment=local”, “-D@appId=myapp”, (project(":").libsDir.toString() + “/” + project.archiveName) )

.inheritIO()

.directory( new File(".")).start()

logger.debug( systemProperties.toString() )

systemProperty ‘@appId’ , ‘myapp’

systemProperty ‘@environment’ , ‘local’ //For Archaius

sleep(2000) //TODO Implement polling and Throw Exception instead of Sleep.

}

doLast{

if ( jettyProcess != null ) {

jettyProcess.destroy()

}

} }

Please let me know if this is a good approach.