diff --git a/baeldung-create-mvn-plugin/.gitignore b/baeldung-create-mvn-plugin/.gitignore new file mode 100644 index 0000000..33653da --- /dev/null +++ b/baeldung-create-mvn-plugin/.gitignore @@ -0,0 +1,31 @@ + +# Files +.classpath +.externalToolBuilders +.gradle +.project +.pydevproject +.settings +.sonar +*~ +*.ipr +*.iml +*.iws +*.swp +*.DS_Store +*.snap.debug +dependency-reduced-pom.xml + +# Directories +.idea/ +.run/ +.venv/ +_site/ +build/ +dist/ +docs/_build/ +gen-java/ +gen-javabean/ +gen-py/ +node_modules/ +target/ diff --git a/baeldung-create-mvn-plugin/README.md b/baeldung-create-mvn-plugin/README.md new file mode 100644 index 0000000..da96a3a --- /dev/null +++ b/baeldung-create-mvn-plugin/README.md @@ -0,0 +1,13 @@ +# Overview +This project shows how to create a Maven plugin. + +# Execution +Call the following instructions to execute the plugin on the command line. + +``` +mvn clean install +mvn de.swingbe:counter-maven-plugin:0.0.1:dependency-counter +``` + +# Links +[Example](https://www.baeldung.com/maven-plugin) diff --git a/baeldung-create-mvn-plugin/pom.xml b/baeldung-create-mvn-plugin/pom.xml new file mode 100644 index 0000000..c86aeb0 --- /dev/null +++ b/baeldung-create-mvn-plugin/pom.xml @@ -0,0 +1,62 @@ + + + + + 4.0.0 + de.swingbe + counter-maven-plugin + maven-plugin + 0.0.1 + + counter-maven-plugin Maven Mojo + http://maven.apache.org + + + + + + + + + 1.8 + 1.8 + + UTF-8 + + + + + + org.apache.maven + maven-plugin-api + 3.6.3 + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.6.0 + provided + + + + org.apache.maven + maven-project + 2.2.1 + + + org.apache.maven + maven-plugin-api + 3.6.3 + compile + + + + diff --git a/baeldung-create-mvn-plugin/settings.xml b/baeldung-create-mvn-plugin/settings.xml new file mode 100644 index 0000000..0788b1d --- /dev/null +++ b/baeldung-create-mvn-plugin/settings.xml @@ -0,0 +1,3 @@ + + de.swingbe + \ No newline at end of file diff --git a/baeldung-create-mvn-plugin/src/main/java/de/swingbe/counter_mvn_plugin/DependencyCounterMojo.java b/baeldung-create-mvn-plugin/src/main/java/de/swingbe/counter_mvn_plugin/DependencyCounterMojo.java new file mode 100644 index 0000000..8c9025e --- /dev/null +++ b/baeldung-create-mvn-plugin/src/main/java/de/swingbe/counter_mvn_plugin/DependencyCounterMojo.java @@ -0,0 +1,30 @@ +package de.swingbe.counter_mvn_plugin; + +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; + +import java.util.List; + +@Mojo(name = "dependency-counter", defaultPhase = LifecyclePhase.COMPILE) +public class DependencyCounterMojo extends AbstractMojo { + + @Parameter(defaultValue = "${project}", required = true, readonly = true) + + MavenProject project; + + public void execute() throws MojoExecutionException, MojoFailureException { + + List dependencies = project.getDependencies(); + + long numDependencies = dependencies.stream().count(); + + getLog().info("Number of dependencies: " + numDependencies); + + } +}