How to run copy task to add js files in build/classes after IDE(intellj) compile/make project

Hi all and thanks for taking time to help in advance. This is the first question I’m posting so please do let me know if this can be improved.
I’m a newbie to gradle and this is my first project. I have gradle.build included at the bottom which downloads tar from nexus repo and then i have tasks to untar and copy the files to $buildDir/classes/main/static/sisplayer. Then i have awar.dependsOn copyPlayer to have the files ready to be added to it. The problem is that i can get to files to be included in the war to work on server and have bootRun{}.dependsOn copyPlayer to have the files before running the app by gradle bootRun but i dont get the files when i run the app on intellij using the main class. I assume i need to hook up the task to be executed before project is compiled so i tried

compileJava.dependsOn copyPlayer
but that is giving out error. I’ve also tried to to use hooks like

gradle.projectsEvaluated {
    preBuild.dependsOn copyPlayer
}

as suggested in here but that’s also comes out with an error. can someone please help. Ive tried to look up but couldn’t find a solution.

Also are there other thing in the config that I can improve as this is my first gradle project. The whole config is as under.

buildscript {
ext {
    springBootVersion = '1.4.1.RELEASE'
}
repositories {
    mavenCentral()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    classpath 'org.springframework:springloaded:1.2.6.RELEASE'
}
}


plugins {
id "org.sonarqube" version "2.2.1"
id "net.saliman.cobertura" version "2.3.2"
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

sourceCompatibility = 1.8
targetCompatibility = 1.8
def playerVersion= "0.4.0-36"
idea {
module {
    inheritOutputDirs = false
    outputDir = file("$buildDir/classes/main/")
}

}

war {

baseName = 'streaming_demo'
version = '0.0.1-SNAPSHOT'
from("$buildDir/classes/main/static/jsplayer"){
    into("WEB-INF/classes/static/jsplayer")
}

}

repositories {
maven {
    url "http://example.com:6590/nexus/content/repositories/frontend-artifacts"
}

maven {
    url "example.com:6590/nexus/content/groups/public/"
}
maven {
    url "http://example.com:6590/nexus/content/repositories/releases/"
}
maven {
    url "http://example.com:6590/nexus/content/repositories/thirdparty/" 
}
maven { url "http://oss.sonatype.org/content/repositories/snapshots/"
}

mavenCentral()
}

configurations {
    jsPlayer
    providedRuntime
}
dependencies {
//  compile group: 'javax.el', name: 'javax.el-api', version: '2.2.4'
    sisPlayer "com.example:jsplayer:$playerVersion@tar.gz"
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-devtools')
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude module: "spring-boot-starter-tomcat"
    }
    compile('org.springframework.boot:spring-boot-starter-web-services')
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4")
    runtime 'mysql:mysql-connector-java:5.1.24'
    compile 'com.microsoft.sqlserver:sqljdbc41:4.1'

    runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')

//  dependencies for using Spock
compile "org.codehaus.groovy:groovy-all:2.4.1"
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"

testRuntime "cglib:cglib-nodep:3.1"          // allows mocking of 

classes (in addition to interfaces)
    testRuntime "org.objenesis:objenesis:2.1"
    // allows mocking of classes without default constructor (together with CGLIB)
}
task wrapper(type: Wrapper) {
    gradleVersion = '3.1'
}
task extractPlayer(type: Copy){
    from tarTree(configurations.jsPlayer.singleFile)
    into "$buildDir/testplayerDownload/"

}
task copyPlayer(type: Copy) {
    dependsOn extractPlayer
    from "$buildDir/testplayerDownload/dist"
    into "$buildDir/classes/main/static/jsplayer"
    doLast {
        delete("$buildDir/testplayerDownload/")
    }
}

build{}.doLast{
    tasks.extractPlayer.execute()
    tasks.copyPlayer.execute()
}

war.dependsOn copyPlayer

bootRun {}.dependsOn copyPlayer

gradle.projectsEvaluated {
    preBuild.dependsOn copyPlayer
}
 cobertura {
    coverageFormats = ['xml']
}