Could not set unknown property 'mainClass' for extension 'application

Actually just modifying the application block to

application {
    mainClassName = 'com.mytestproject.Main'

does the same thing.

The problem seems to be that there used to be a mainClass attribute on the org.gradle.api.plugins.internal.DefaultJavaApplication class, but it later got renamed to mainClassName, rendering previous tutorials invalid.

You could try this (based off the source code):

application {

Modify build.gradle to this :

apply plugin: "application"

mainClassName = "com.mytestproject.Main"

sourceCompatibility = 1.8
targetCompatibility = 1.8

group 'com.mytestproject'
version '1.0-SNAPSHOT'

repositories {

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'

Run this commmand : ./gradlew build