1

I am trying to extend an existing build.gradle so that it updates jacocoTestReport so that XML reports are generated as they are now required by SonarQube

// allprojects {
// initscript {
rootProject {
  plugins {
    id 'jacoco'
  }
  //apply plugin: 'jacoco'
  jacocoTestReport {
    reports {
      xml.enabled = true
      html.enabled = true
    }
  }
}

I tried to use ./gradlew -I jacoco.gradle check but I am getting errors like

Could not find method plugins() for arguments [init_4poyb2mng02b0u77g0shf960p$_run_closure1$_closure2@1821f380] on root project 'template-ms' of type org.gradle.api.Project.
Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

1 Answers1

-2

Using the following answer in Gradle Jacoco - Could not find method jacocoTestReport() which indicated that the java plugin needs to be applied this is the result

allprojects {
  apply plugin: 'java'
  apply plugin: 'jacoco'
  jacocoTestReport {
    reports {
      xml.enabled = true
      html.enabled = true
    }
  }
}

and ./gradlew -I jacoco.gradle check jacocoTestReport works correctly now

Also as a bonus, I was able to add a dependency

allprojects {
  apply plugin: 'java'
  apply plugin: 'jacoco'
  jacocoTestReport {
    reports {
      xml.enabled = true
      html.enabled = true
    }
  }
  check.dependsOn(jacocoTestReport)
}

So developers just need to do ./gradlew -I jacoco.gradle check

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265