Search code examples
groovyjargradleexecutable-jarspock

Create a Groovy executable jar with Spock test set as to be executed


I want to create jar with two groovy files, AppLogic.groovy which consists of two few groovy classes and another file, AppSpec that has Spock test suite and I would like to have this Spock class executed (set as executable). How can I create such jar with all dependencies? I found sth similar for jUnit here: how to export (JUnit) test suite as executable jar but could not adapt it for my needs.

I use gradle for build, here is my build.gradle file:

group 'someGroup'
version '1.0'

apply plugin: 'groovy'
apply plugin: 'java'
apply plugin:'application'

sourceCompatibility = 1.7

repositories {

//some repos here

maven { url "http://repo.maven.apache.org/maven2" }
}

dependencies {
//some dependencies here
}

I was browsing around and found SpockRuntime, but I do not know if and how I can use it to achive my goal.


Solution

  • And the winner is:

    static void main(String[] args) {
        EmbeddedSpecRunner embeddedSpecRunner = new EmbeddedSpecRunner()
        embeddedSpecRunner.runClass(MySpec)
    }