WarArchiveClassesPlugin implements Plugin<Project> { @Override public void apply(Project project) { project.getTasks().withType(War.class, war -> { WarArchiveClassesConvention archiveClassesConvention = new WarArchiveClassesConvention(); war.getConvention().getPlugins().put("archiveClasses", archiveClassesConvention); Jar warClassesJar = project.getTasks().create(war.getName() + "ClassesJar", Jar.class); warClassesJar.getArchiveBaseName().convention(war.getArchiveBaseName()); warClassesJar.getArchiveAppendix().convention(war.getArchiveAppendix()); warClassesJar.getArchiveVersion().convention(war.getArchiveVersion()); warClassesJar.getArchiveClassifier().convention(war.getArchiveClassifier()); project.afterEvaluate(p -> { warClassesJar.setEnabled(archiveClassesConvention.isArchiveClasses()); if (archiveClassesConvention.isArchiveClasses()) { FileCollection warClasspath = war.getClasspath(); warClassesJar.from(warClasspath != null ? warClasspath.filter(File::isDirectory) : Collections.emptyList()); war.setClasspath(warClasspath == null ? null : warClasspath.filter(File::isFile).plus(project.files(warClassesJar))); } }); }); }  @Override void apply(Project project);  }
@Test public void testArchiveClassesProperty() { project.getPlugins().apply(WarPlugin.class); project.getPlugins().apply(WarArchiveClassesPlugin.class); War warTask = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); assertThat(warTask.hasProperty("archiveClasses")).isTrue(); assertThat(warTask.property("archiveClasses")).isInstanceOf(Boolean.class); }