buildscript { ext.kotlin_version = '1.3.41' repositories { mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } def printOutput(def output) { return tasks.create("printOutput") { for (line in output.toString().readLines()) { println "#educational_plugin" + line } } } allprojects { apply plugin: 'java' apply plugin: 'kotlin' repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect" } compileKotlin.destinationDir = compileJava.destinationDir compileKotlin { kotlinOptions.jvmTarget = "1.8" } compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } } apply plugin: 'application' sourceCompatibility = 1.8 dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' compile project(':util').sourceSets.main.output testCompile project(':util').sourceSets.test.output } def srcList = [] def testList = [] rootProject.projectDir.eachDirRecurse { if (!isTaskDir(it) || it.path.contains(".idea") || "util".equals(it.path)) { return } def srcDir = new File(it, "src") srcList.add(srcDir) def testDir = new File(it, "test") testList.add(testDir) } sourceSets { main { java { srcDirs = srcList } kotlin { srcDirs = srcList } } test { java { srcDirs = testList } kotlin { srcDirs = testList } } } static def isTaskDir(File dir) { return new File(dir, "src").exists() } mainClassName = project.hasProperty("mainClass") ? project.getProperty("mainClass") : "" test { outputs.upToDateWhen { false } afterTest { TestDescriptor test, TestResult result -> if (result.resultType == TestResult.ResultType.FAILURE) { def message = result.exception?.message ?: "Wrong answer" def lines = message.readLines() println "#educational_plugin FAILED + " + lines[0] lines[1..-1].forEach { line -> println "#educational_plugin" + line } // we need this to separate output of different tests println } } } def runOutput = new ByteArrayOutputStream() tasks.run.setStandardOutput(runOutput) tasks.run.doLast { printOutput(runOutput) } project(':util') { dependencies { compile group: 'junit', name: 'junit', version: '4.12' } }