io.freefair.gradle.plugins.maven.war.WarAttachClassesPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-plugin Show documentation
Show all versions of maven-plugin Show documentation
Collection of Maven related Gradle plugins
package io.freefair.gradle.plugins.maven.war;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.WarPlugin;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.bundling.War;
public class WarAttachClassesPlugin implements Plugin {
@Override
public void apply(Project project) {
project.getPlugins().apply(WarPlugin.class);
Property attachClasses = project.getObjects().property(Boolean.class).convention(false);
Property classesClassifier = project.getObjects().property(String.class).convention("classes");
WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention(attachClasses, classesClassifier);
project.getTasks().named(WarPlugin.WAR_TASK_NAME, War.class, war -> {
war.getConvention().getPlugins().put("attachClasses", attachClassesConvention);
war.getExtensions().add("attachClasses", attachClasses);
war.getExtensions().add("classesClassifier", classesClassifier);
});
project.afterEvaluate(p -> {
if (attachClasses.get()) {
TaskProvider jar = project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class, j ->
j.getArchiveClassifier().convention(classesClassifier)
);
project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar);
}
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy