Search in sources :

Example 1 with DefaultWarPluginConvention

use of org.gradle.api.plugins.internal.DefaultWarPluginConvention in project gradle by gradle.

the class WarPlugin method apply.

@Override
public void apply(final Project project) {
    project.getPluginManager().apply(JavaPlugin.class);
    final WarPluginConvention pluginConvention = new DefaultWarPluginConvention(project);
    project.getConvention().getPlugins().put("war", pluginConvention);
    project.getTasks().withType(War.class).configureEach(task -> {
        task.getWebAppDirectory().convention(project.getLayout().dir(project.provider(() -> pluginConvention.getWebAppDir())));
        task.from(task.getWebAppDirectory());
        task.dependsOn((Callable) () -> project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
        task.classpath((Callable) () -> {
            FileCollection runtimeClasspath = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
            Configuration providedRuntime = project.getConfigurations().getByName(PROVIDED_RUNTIME_CONFIGURATION_NAME);
            return runtimeClasspath.minus(providedRuntime);
        });
    });
    TaskProvider<War> war = project.getTasks().register(WAR_TASK_NAME, War.class, warTask -> {
        warTask.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
        warTask.setGroup(BasePlugin.BUILD_GROUP);
    });
    PublishArtifact warArtifact = new LazyPublishArtifact(war, ((ProjectInternal) project).getFileResolver());
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
    configureConfigurations(project.getConfigurations());
    configureComponent(project, warArtifact);
}
Also used : LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) DefaultWarPluginConvention(org.gradle.api.plugins.internal.DefaultWarPluginConvention) Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) War(org.gradle.api.tasks.bundling.War) FileCollection(org.gradle.api.file.FileCollection) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultWarPluginConvention(org.gradle.api.plugins.internal.DefaultWarPluginConvention)

Aggregations

Configuration (org.gradle.api.artifacts.Configuration)1 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)1 FileCollection (org.gradle.api.file.FileCollection)1 LazyPublishArtifact (org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact)1 DefaultArtifactPublicationSet (org.gradle.api.internal.plugins.DefaultArtifactPublicationSet)1 DefaultWarPluginConvention (org.gradle.api.plugins.internal.DefaultWarPluginConvention)1 War (org.gradle.api.tasks.bundling.War)1 DeprecatableConfiguration (org.gradle.internal.deprecation.DeprecatableConfiguration)1