apply plugin: 'java'

defaultTasks 'javaexecTask', 'javaexecByMethod'

task javaexecTask(type: JavaExec, dependsOn: classes) {
    testFile = file("$buildDir/$name")
    classpath(sourceSets.main.classesDir)
    main = 'org.gradle.TestMain'
    args testFile.absolutePath
    doLast {
        assert testFile.exists()
    }
}

task javaexecByMethod(dependsOn: classes) {
    testFile = file("$buildDir/$name")
    doFirst {
        javaexec {
            classpath(sourceSets.main.classesDir)
            main = 'org.gradle.TestMain'
            args testFile.absolutePath
        }
    }
    doLast {
        assert testFile.exists()
    }
}