WarOverlayPlugin implements Plugin<Project> { @Override public void apply(Project project) { this.project = project; project.getPluginManager().apply(WarPlugin.class); project.getTasks().withType(War.class, warTask -> { NamedDomainObjectContainer<WarOverlay> warOverlays = project.container(WarOverlay.class, name -> new WarOverlay(name, warTask)); warTask.getExtensions().add("overlays", warOverlays); Configuration warOverlayClasspath = project.getConfigurations().create(warTask.getName() + "OverlayClasspath"); warTask.getExtensions().add("overlayClasspath", warOverlayClasspath); if (warTask.getName().equals(WarPlugin.WAR_TASK_NAME)) { project.getConfigurations().getByName(COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(warOverlayClasspath); project.getConfigurations().getByName(TEST_IMPLEMENTATION_CONFIGURATION_NAME).extendsFrom(warOverlayClasspath); } project.afterEvaluate(p -> warOverlays.all(overlay -> { if (overlay.isEnabled()) { configureOverlay(overlay); } else { Collection<CopySpecInternal> children = (Collection<CopySpecInternal>) overlay.getWarTask().getRootSpec().getChildren(); children.remove(overlay.getWarCopySpec()); } })); }); }  @Override void apply(Project project);  }
@Test public void testProperties() { Project project = ProjectBuilder.builder().build(); project.getPlugins().apply(WarPlugin.class); project.getPlugins().apply(WarOverlayPlugin.class); Task warTask = project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); assertThat(warTask.hasProperty("overlays")).isTrue(); assertThat(warTask.property("overlays")).isInstanceOf(DomainObjectCollection.class); }