Could not set unknown property 'reportsDirectory' for object of type org.gradle.testing.jacoco.plugins.JacocoPluginExtension

Hi,
I am trying to create a simple POC (Proof Of Concept) project to check code coverage with JaCoCo. Referring Building Java Applications Sample
Unfortunately, my “gradlew run” is not running clean due to below error. Tried with different values for toolVersion. No luck. Could someone help me out here…!!! Thanks in advance for your help.


  • What went wrong:

A problem occurred evaluating root project ‘myjava’.

Could not set unknown property ‘reportsDirectory’ for object of type org.gradle.testing.jacoco.plugins.JacocoPluginExtension.


Here is my build.gradle file


plugins {
// Apply the java plugin to add support for Java
id ‘java’

// Apply the application plugin to add support for building a CLI application
id 'application'

// Enable code coverage with jacoco
id 'jacoco'

}

repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}

dependencies {
// This dependency is used by the application.
implementation ‘com.google.guava:guava:27.1-jre’

// Use JUnit test framework
testImplementation 'junit:junit:4.12'

}

application {
// Define the main class for the application
mainClassName = ‘myjava.App’
}
jacoco {
applyTo run
toolVersion = “2.5.4”
reportsDirectory = layout.buildDirectory.dir(‘customJacocoReportDir’)
// reportsDir = ‘/d0/home/varnepalli/javatest-gradle/build/reports/jacoco’
// reportsDirectory = ‘/d0/home/varnepalli/javatest-gradle/build/reports/jacoco’
}

tasks.register(‘applicationCodeCoverageReport’, JacocoReport) {
executionData run
sourceSets sourceSets.main
}

test {
finalizedBy jacocoTestReport // report is always generated after tests run
jacoco {
destinationFile = layout.buildDirectory.file(‘jacoco/jacocoTest.exec’).get().asFile
classDumpDir = layout.buildDirectory.dir(‘jacoco/classpathdumps’).get().asFile
}
}

jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir(‘jacocoHtml’)
}
}