From dbb25da0b078a1550b0ed0e717bd1626079007ef Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 28 Jun 2020 13:47:27 +0530 Subject: [PATCH] JAVA-49: Moved maven-custom-plugin to maven-modules --- maven-modules/maven-custom-plugin/README.md | 7 ++ .../counter-maven-plugin/pom.xml | 80 +++++++++++++++++++ .../validator/DependencyCounterMojo.java | 45 +++++++++++ maven-modules/maven-custom-plugin/pom.xml | 21 +++++ .../maven-custom-plugin/usage-example/pom.xml | 51 ++++++++++++ 5 files changed, 204 insertions(+) create mode 100644 maven-modules/maven-custom-plugin/README.md create mode 100644 maven-modules/maven-custom-plugin/counter-maven-plugin/pom.xml create mode 100644 maven-modules/maven-custom-plugin/counter-maven-plugin/src/main/java/com/baeldung/maven/plugin/validator/DependencyCounterMojo.java create mode 100644 maven-modules/maven-custom-plugin/pom.xml create mode 100644 maven-modules/maven-custom-plugin/usage-example/pom.xml diff --git a/maven-modules/maven-custom-plugin/README.md b/maven-modules/maven-custom-plugin/README.md new file mode 100644 index 0000000000..1889036ce3 --- /dev/null +++ b/maven-modules/maven-custom-plugin/README.md @@ -0,0 +1,7 @@ +## Apache Maven + +This module contains articles about creating a custom plugin in Maven. + +### Relevant Articles + +- [How to Create a Maven Plugin](https://www.baeldung.com/maven-plugin) diff --git a/maven-modules/maven-custom-plugin/counter-maven-plugin/pom.xml b/maven-modules/maven-custom-plugin/counter-maven-plugin/pom.xml new file mode 100644 index 0000000000..7ddf5b739c --- /dev/null +++ b/maven-modules/maven-custom-plugin/counter-maven-plugin/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + com.baeldung + counter-maven-plugin + 0.0.1-SNAPSHOT + counter-maven-plugin Maven Mojo + maven-plugin + http://maven.apache.org + + + Baeldung + https://www.baeldung.com/ + + + + + org.apache.maven + maven-plugin-api + ${maven-plugin-api.version} + + + org.apache.maven.plugin-tools + maven-plugin-annotations + ${maven-plugin-annotations.version} + provided + + + org.apache.maven + maven-project + ${maven-project.version} + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + ${maven-plugin-plugin.version} + + + org.apache.maven.plugins + maven-site-plugin + ${maven-site-plugin.version} + + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + + + + report + + + + + + + + + 1.8 + 1.8 + 3.6.2 + 3.6.0 + 2.2.1 + 3.6.0 + 3.8.2 + + + \ No newline at end of file diff --git a/maven-modules/maven-custom-plugin/counter-maven-plugin/src/main/java/com/baeldung/maven/plugin/validator/DependencyCounterMojo.java b/maven-modules/maven-custom-plugin/counter-maven-plugin/src/main/java/com/baeldung/maven/plugin/validator/DependencyCounterMojo.java new file mode 100644 index 0000000000..4bb53b20cf --- /dev/null +++ b/maven-modules/maven-custom-plugin/counter-maven-plugin/src/main/java/com/baeldung/maven/plugin/validator/DependencyCounterMojo.java @@ -0,0 +1,45 @@ +package com.baeldung.maven.plugin.validator; + +import java.util.List; + +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +/** + * Counts the number of maven dependencies of a project. + * + * It can be filtered by scope. + * + */ +@Mojo(name = "dependency-counter", defaultPhase = LifecyclePhase.COMPILE) +public class DependencyCounterMojo extends AbstractMojo { + + /** + * Scope to filter the dependencies. + */ + @Parameter(property = "scope") + String scope; + + /** + * Gives access to the Maven project information. + */ + @Parameter(defaultValue = "${project}", required = true, readonly = true) + MavenProject project; + + public void execute() throws MojoExecutionException, MojoFailureException { + List dependencies = project.getDependencies(); + + long numDependencies = dependencies.stream() + .filter(d -> (scope == null || scope.isEmpty()) || scope.equals(d.getScope())) + .count(); + + getLog().info("Number of dependencies: " + numDependencies); + } + +} diff --git a/maven-modules/maven-custom-plugin/pom.xml b/maven-modules/maven-custom-plugin/pom.xml new file mode 100644 index 0000000000..ad22c735ff --- /dev/null +++ b/maven-modules/maven-custom-plugin/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + maven-custom-plugin + 0.0.1-SNAPSHOT + maven-custom-plugin + pom + + + com.baeldung + maven-modules + 0.0.1-SNAPSHOT + + + + counter-maven-plugin + usage-example + + + \ No newline at end of file diff --git a/maven-modules/maven-custom-plugin/usage-example/pom.xml b/maven-modules/maven-custom-plugin/usage-example/pom.xml new file mode 100644 index 0000000000..f512fc104d --- /dev/null +++ b/maven-modules/maven-custom-plugin/usage-example/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + com.baeldung + usage-example + 0.0.1-SNAPSHOT + pom + + + + org.apache.commons + commons-lang3 + ${commons.lang3.version} + + + junit + junit + ${junit.version} + test + + + + + + + com.baeldung + counter-maven-plugin + 0.0.1-SNAPSHOT + + + + dependency-counter + + + + + test + + + + + + + 3.9 + 4.12 + + +