WarAttachClassesPlugin implements Plugin<Project> { @Override public void apply(Project project) { project.getPlugins().apply(WarPlugin.class); WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention(); project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class, war -> war.getConvention().getPlugins().put("attachClasses", attachClassesConvention) ); project.afterEvaluate(p -> { if (attachClassesConvention.isAttachClasses()) { TaskProvider<Jar> jar = project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, j -> j.getArchiveClassifier().convention(attachClassesConvention.getClassesClassifier()) ); project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar); } }); }  @Override void apply(Project project);  }
@Test public void testProperties() { project.getPlugins().apply(WarPlugin.class); project.getPlugins().apply(WarAttachClassesPlugin.class); War warTask = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); assertThat(warTask.hasProperty("attachClasses")).isTrue(); assertThat(warTask.property("attachClasses")).isInstanceOf(Boolean.class); assertThat(warTask.hasProperty("classesClassifier")).isTrue(); assertThat(warTask.property("classesClassifier")).isInstanceOf(String.class); }