All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.freefair.gradle.plugins.maven.central.ValidatePomsPlugin Maven / Gradle / Ivy

There is a newer version: 8.11
Show newest version
package io.freefair.gradle.plugins.maven.central;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.publish.maven.tasks.GenerateMavenPom;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

/**
 * @author Lars Grefer
 */
public class ValidatePomsPlugin implements Plugin {

    @Override
    public void apply(Project project) {
        TaskProvider validateAll = project.getTasks().register("validatePomFiles", t -> {
            t.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
        });

        project.getTasks().withType(GenerateMavenPom.class, generateMavenPom -> {

            String checkTaskName;

            if (generateMavenPom.getName().startsWith("generate")) {
                checkTaskName = "validate" + generateMavenPom.getName().substring(8);
            }
            else {
                checkTaskName = "validate" + generateMavenPom.getName();
            }

            TaskProvider validateMavenPom = project.getTasks().register(checkTaskName, ValidateMavenPom.class, t -> {
                t.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
                String description = generateMavenPom.getDescription();
                if (description != null) {
                    t.setDescription(description.replace("Generates", "Validates"));
                }
            });

            validateAll.configure(all -> all.dependsOn(validateMavenPom));

            project.getPlugins().withType(LifecycleBasePlugin.class, lbp -> {
                project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(check -> {
                    check.dependsOn(validateMavenPom);
                });
            });

            validateMavenPom.configure(v -> {
                v.dependsOn(generateMavenPom);
                v.getPomFile().set(project.getLayout().file(project.provider(generateMavenPom::getDestination)));
            });
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy