really dumb question, do I actually need to apply ...
# community-support
c
really dumb question, do I actually need to apply the
JavaBasePlugin
for this to work properly? I'm just thinking about it, and doubting that I should have added it, but then maybe a project couldn't work without it... esp if
CHECK
and
Test
come from it.
Copy code
public class CoveragePlugin implements Plugin<Project> {

  @Override
  public void apply(@NonNull Project project) {
    project.getPlugins().apply(JavaBasePlugin.class);
    project.getPlugins().apply(JacocoPlugin.class);
    var coverage = project.getExtensions().create("coverage", CoveragePluginExtension.class);

    var tasks = project.getTasks();
    tasks
      .withType(JacocoReport.class)
      .configureEach(jacocoReport -> {
        var tests = tasks.withType(Test.class);
        jacocoReport.dependsOn(tests);
        tests.forEach(jacocoReport::executionData);
      });

    tasks.named(JavaBasePlugin.CHECK_TASK_NAME, task -> task.dependsOn(tasks.withType(JacocoReport.class)));

    tasks
      .withType(JacocoCoverageVerification.class)
      .configureEach(verification -> {
        verification.dependsOn(tasks.withType(JacocoReport.class));
        // execution data needs to be aggregated from all exec files in the project for multi jvm test suite testing
        verification.executionData(tasks.withType(JacocoReport.class).stream().map(JacocoReport::getExecutionData));
        verification.violationRules(rules -> {
          rules.rule(r -> {
            r.limit(limit -> limit.setMinimum(coverage.getMinimum().orElse(0.9).map(BigDecimal::valueOf).get()));
          });
        });
      });
  }
}
v
Test
is a built-in type, so it is always available. And
check
is not coming from
java-base
, but
lifecycle-base
.
👍 1