0

Related to How to configure JaCoCo maven plugin from command line

I want to know if there is a way of doing this in Gradle.

Force the inclusion of the JaCoCo plugin in the command line instead of adding the apply plugin 'jacoco'.

Thanks in advance.

dcalap
  • 1,048
  • 2
  • 13
  • 37

1 Answers1

1

How to configure JaCoCo Gradle plugin from command line

The same way as other Gradle plugins - using initialization scripts, however be aware of https://github.com/gradle/gradle/issues/1262 and https://github.com/gradle/gradle/issues/1322 which among other things say that plugins that are not part of Gradle distribution can not be applied using id and should use type. While JaCoCo plugin is part of distribution, here is example that uses type - given following jacoco.gradle

allprojects {
  apply plugin: org.gradle.testing.jacoco.plugins.JacocoPlugin
}

execution of gradle --init-script jacoco.gradle tasks --all shows that task jacocoTestReport appears in project.

Godin
  • 9,801
  • 2
  • 39
  • 76
  • Thanaks Godin but the point of my question is to force the use of the JaCoCo plugin in a jenkins pipeline. The developer has access to the build.gradle, so, it can be easily removed. If you execute the plugin like in maven, it doesn't matter if developers get rid of it in the pom. It will be always executed. That's why I need to inject the plugin in the ./gradlew command. – dcalap Feb 25 '19 at 10:25
  • 1
    @dcalap and this is exactly what was shown - `build.gradle` has no plugin, plugin is defined in `jacoco.gradle`, which is included in build by addition of `--init-script jacoco.gradle` to `gradle` command – Godin Feb 25 '19 at 10:33