JacocoTestReport task always skipped

I add DoLast part to test task and also add doLast part to JacocoTestReport task, but when i running JacocoTestReport task, JacocoTestReport always skipped, and copy task always say NO-SOURCE ,Pls help:

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'base' 	 

sourceCompatibility = 1.7
targetCompatibility = 1.7
compileJava.options.encoding = 'UTF-8'  
version = '1.0'   
  
sourceSets {  
 	main {

        java{
            srcDirs = ['src/main/java']
        }

        resources {
            srcDirs = ['src/main/resources']
        }
    }
     test {

          java{
            srcDirs = ['src/test/java']
               }

        resources {
            srcDirs = ['src/test/resources']
        }
    }
}
  
repositories {  
    mavenCentral()  
}  

jacoco {
    toolVersion = "0.7.6.201602180812"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

dependencies {  
   
   	testCompile(['org.testng:testng:6.8.8'])
    compile(['com.google.code.gson:gson:2.8.0']) 
    compile fileTree(dir: 'lib', include: ['*.jar'])
} 

test.doLast{
			      
  	// enable TestNG support (default is JUnit)
	useTestNG() {
	
        suites 'src/test/java/TestNG.xml'
        useDefaultListeners = true
    }
	
  
    jacoco {
        append = false
        destinationFile = file("$buildDir/jacoco/TestNG.exec")
        //classDumpFile = file("$buildDir/jacoco/classpathdumps")
    }
   
}
task applicationCodeCoverageReport(type: JacocoReport, dependsOn:test){
 	
  sourceSets sourceSets.main
	group = 'Reporting' 
	description = 'Generate Jacoco coverage reports after running tests.'
	executionData = files('build/jacoco/TestNG.exec')
 	doFirst {
             delete fileTree (dir: "${buildDir}/classes", include: "**/*.class")
     		
     		 }
		reports {
				xml{
					enabled true
					destination 'build/reports/jacoco/jacoco.xml'
					}
					
				csv.enabled false
				
				html{
					enabled true
					destination 'build/jacocoHtml'
					}
				}
     doLast{		 
	println "JACOCO Dolast************************"			
	 }
}

task copyConfigureFiles(type: Copy) doLast{
	from 'config'
	into 'target/config/'
}

output:

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test
:applicationCodeCoverageReport SKIPPED
:copyConfigureFiles NO-SOURCE

Hi,

you are actually configuring the test task during execution (doLast happens after the task’s actions executed). You should be configuring the test task in the configuration phase (without the doLast).
For your build script, when the task tries to execute, it is not yet configured to use TestNG (doLast did not run yet) - so it uses JUnit (the default) and doesn’t find any JUnit tests.
The jacoco block also should not be nested in doLast. It is a top level block, configuring the jacoco extension.

Cheers,
Stefan

thanks for your reply.
want to confirm some issues. look forward to your reply.
(1) does test task just configured in configuration not execution phase ?
(2) if i want to use jacoco plugin, it only can use in configuration phase . am i right ?
(3) two tasks in the following :
task copyConfigA(type: Copy) {
from 'config’
into ‘target/config/’
}

task copyConfigB(type: Copy) doLast {
from 'config’
into ‘target/config/’
}

copyConfigA does work , but copyConfigB does not work, why?

Please have a look at https://docs.gradle.org/current/userguide/potential_traps.html#sec:configuration_and_execution_phase and https://docs.gradle.org/current/userguide/build_lifecycle.html.
These chapters should answer your question. The main takeaway is that tasks need to be configured during the configuration phase (without doLast or doFirst) while actions of a task should happen in the execution phase (added via doLast or doFirst).
Your questions:

  1. Yes
  2. I don’t know what you mean with use. Configure in configuration phase.
  3. copyConfigB is configured during execution phase and therefore does not work.

thanks.
It’s my fault for question 2 . I try to use another way to explain this issue.

for example :

task copyConfigA(type: Copy) {
from 'config’
into ‘target/config/’
}

cmd : gradle copyConfigA
I got it that from ‘config’ , into ‘target/config/’ expressions are work in configuration phase, if they are all just configuration, when this task execute copy action ? what does copy task do in execution phase ?