org.gradle.api.publish.maven.tasks.GenerateMavenPom Java Examples

The following examples show how to use org.gradle.api.publish.maven.tasks.GenerateMavenPom. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MavenPublishPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createGeneratePomTask(CollectionBuilder<Task> tasks, final MavenPublicationInternal publication, String publicationName) {
    String descriptorTaskName = String.format("generatePomFileFor%sPublication", capitalize(publicationName));
    tasks.create(descriptorTaskName, GenerateMavenPom.class, new Action<GenerateMavenPom>() {
        public void execute(final GenerateMavenPom generatePomTask) {
            generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName()));
            generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
            generatePomTask.setPom(publication.getPom());

            ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping();
            descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
                public Object call() throws Exception {
                    return new File(generatePomTask.getProject().getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml");
                }
            });

            // Wire the generated pom into the publication.
            publication.setPomFile(generatePomTask.getOutputs().getFiles());
        }
    });
}
 
Example #2
Source File: MavenPublishTaskModelRule.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createGeneratePomTask(final MavenPublicationInternal publication, String publicationName) {
    String descriptorTaskName = String.format("generatePomFileFor%sPublication", capitalize(publicationName));
    GenerateMavenPom generatePomTask = project.getTasks().create(descriptorTaskName, GenerateMavenPom.class);
    generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName()));
    generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    generatePomTask.setPom(publication.getPom());

    ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping();
    descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
        public Object call() throws Exception {
            return new File(project.getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml");
        }
    });

    // Wire the generated pom into the publication.
    publication.setPomFile(generatePomTask.getOutputs().getFiles());
}
 
Example #3
Source File: ValidatePomsPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getTasks().withType(GenerateMavenPom.class, generateMavenPom -> {

        String checkTaskName;

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

        ValidateMavenPom validateMavenPom = project.getTasks().create(checkTaskName, ValidateMavenPom.class);

        project.afterEvaluate(p -> {

            Task check = project.getTasks().findByName(JavaBasePlugin.CHECK_TASK_NAME);
            if (check != null) {
                check.dependsOn(validateMavenPom);
            }

            validateMavenPom.dependsOn(generateMavenPom);
            validateMavenPom.getPomFile().set(generateMavenPom.getDestination());
        });
    });
}
 
Example #4
Source File: ValidatePomsPlugin.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
    project.getTasks().withType(GenerateMavenPom.class, generateMavenPom -> {

        String checkTaskName;

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

        ValidateMavenPom validateMavenPom = project.getTasks().create(checkTaskName, ValidateMavenPom.class);

        project.afterEvaluate(p -> {

            Task check = project.getTasks().findByName(JavaBasePlugin.CHECK_TASK_NAME);
            if (check != null) {
                check.dependsOn(validateMavenPom);
            }

            validateMavenPom.dependsOn(generateMavenPom);
            validateMavenPom.getPomFile().set(generateMavenPom.getDestination());
        });
    });
}
 
Example #5
Source File: MavenPublishPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createGeneratePomTask(CollectionBuilder<Task> tasks, final MavenPublicationInternal publication, String publicationName) {
    String descriptorTaskName = String.format("generatePomFileFor%sPublication", capitalize(publicationName));
    tasks.create(descriptorTaskName, GenerateMavenPom.class, new Action<GenerateMavenPom>() {
        public void execute(final GenerateMavenPom generatePomTask) {
            generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName()));
            generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
            generatePomTask.setPom(publication.getPom());

            ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping();
            descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
                public Object call() throws Exception {
                    return new File(generatePomTask.getProject().getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml");
                }
            });

            // Wire the generated pom into the publication.
            publication.setPomFile(generatePomTask.getOutputs().getFiles());
        }
    });
}
 
Example #6
Source File: MavenPublishTaskModelRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createGeneratePomTask(final MavenPublicationInternal publication, String publicationName) {
    String descriptorTaskName = String.format("generatePomFileFor%sPublication", capitalize(publicationName));
    GenerateMavenPom generatePomTask = project.getTasks().create(descriptorTaskName, GenerateMavenPom.class);
    generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName()));
    generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    generatePomTask.setPom(publication.getPom());

    ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping();
    descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
        public Object call() throws Exception {
            return new File(project.getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml");
        }
    });

    // Wire the generated pom into the publication.
    publication.setPomFile(generatePomTask.getOutputs().getFiles());
}
 
Example #7
Source File: MavenPluginPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JavaPlugin.class);
    MavenPublishJavaPlugin mavenPublishJavaPlugin = project.getPlugins().apply(MavenPublishJavaPlugin.class);

    // https://github.com/gradle/gradle/issues/10555#issue-492150084
    if (project.getGradle().getGradleVersion().matches("5\\.6(\\.[12])?")) {
        mavenPublishJavaPlugin.getPublication().getPom().withXml(xmlProvider ->
                xmlProvider.asNode().appendNode("packaging", "maven-plugin")
        );
    }
    else {
        mavenPublishJavaPlugin.getPublication().getPom().setPackaging("maven-plugin");
    }

    TaskProvider<GenerateMavenPom> generateMavenPom = project.getTasks().named("generatePomFileForMavenJavaPublication", GenerateMavenPom.class);

    TaskProvider<DescriptorGeneratorTask> descriptorGeneratorTaskProvider = project.getTasks().register("generateMavenPluginDescriptor", DescriptorGeneratorTask.class, generateMavenPluginDescriptor -> {

        generateMavenPluginDescriptor.dependsOn(generateMavenPom);
        generateMavenPluginDescriptor.getPomFile().set(generateMavenPom.get().getDestination());

        generateMavenPluginDescriptor.getOutputDirectory().set(
                project.getLayout().getBuildDirectory().dir("maven-plugin")
        );

        SourceSet main = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main");
        generateMavenPluginDescriptor.getSourceDirectories().from(main.getAllJava().getSourceDirectories());
        JavaCompile javaCompile = (JavaCompile) project.getTasks().getByName(main.getCompileJavaTaskName());

        generateMavenPluginDescriptor.getClassesDirectories().from(javaCompile);
        generateMavenPluginDescriptor.getEncoding().convention(javaCompile.getOptions().getEncoding());
    });

    project.getTasks().named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, ProcessResources.class)
            .configure(processResources -> processResources.from(descriptorGeneratorTaskProvider));
}
 
Example #8
Source File: MavenPluginPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    project.getPlugins().apply(JavaPlugin.class);
    MavenPublishJavaPlugin mavenPublishJavaPlugin = project.getPlugins().apply(MavenPublishJavaPlugin.class);

    // https://github.com/gradle/gradle/issues/10555#issue-492150084
    if (project.getGradle().getGradleVersion().matches("5\\.6(\\.[12])?")) {
        mavenPublishJavaPlugin.getPublication().getPom().withXml(xmlProvider ->
                xmlProvider.asNode().appendNode("packaging", "maven-plugin")
        );
    }
    else {
        mavenPublishJavaPlugin.getPublication().getPom().setPackaging("maven-plugin");
    }

    TaskProvider<GenerateMavenPom> generateMavenPom = project.getTasks().named("generatePomFileForMavenJavaPublication", GenerateMavenPom.class);

    TaskProvider<DescriptorGeneratorTask> descriptorGeneratorTaskProvider = project.getTasks().register("generateMavenPluginDescriptor", DescriptorGeneratorTask.class, generateMavenPluginDescriptor -> {

        generateMavenPluginDescriptor.dependsOn(generateMavenPom);
        generateMavenPluginDescriptor.getPomFile().set(generateMavenPom.get().getDestination());

        generateMavenPluginDescriptor.getOutputDirectory().set(
                project.getLayout().getBuildDirectory().dir("maven-plugin")
        );

        SourceSet main = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main");
        generateMavenPluginDescriptor.getSourceDirectories().from(main.getAllJava().getSourceDirectories());
        JavaCompile javaCompile = (JavaCompile) project.getTasks().getByName(main.getCompileJavaTaskName());

        generateMavenPluginDescriptor.getClassesDirectories().from(javaCompile);
        generateMavenPluginDescriptor.getEncoding().convention(javaCompile.getOptions().getEncoding());
    });

    project.getTasks().named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, ProcessResources.class)
            .configure(processResources -> processResources.from(descriptorGeneratorTaskProvider));
}