feat(baeldung-create-mvn-plugin): initial commit

This commit is contained in:
dancingCycle 2022-01-04 06:57:44 -05:00
parent 15866d920d
commit 9c0034efdc
5 changed files with 139 additions and 0 deletions

31
baeldung-create-mvn-plugin/.gitignore vendored Normal file
View File

@ -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/

View File

@ -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)

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!--TODO Compare with mvn_base project!-->
<modelVersion>4.0.0</modelVersion>
<groupId>de.swingbe</groupId>
<artifactId>counter-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1</version>
<name>counter-maven-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<!--<licenses>
<license>
<name>GNU General Public License</name>
<url>https://www.gnu.org/licenses/gpl-3.0.txt</url>
</license>
</licenses>-->
<scm>
<!--<url>https://github.com/Software-Ingenieur-Begerad/sandbox-java</url>-->
</scm>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<!-- Other properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!--This plugin contains necessary classes and interfaces to create a MOJO.-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
</dependency>
<!--This plugin comes in handy to use annotations in our clases.-->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<!--This plugin lets us access the information about the project where we are including the plugin.-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,3 @@
<pluginGroups>
<pluginGroup>de.swingbe</pluginGroup>
</pluginGroups>

View File

@ -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<Dependency> dependencies = project.getDependencies();
long numDependencies = dependencies.stream().count();
getLog().info("Number of dependencies: " + numDependencies);
}
}