Adding displaying info about current project.

master
Tomasz Półgrabia 2022-01-24 20:43:45 +01:00
parent d9c5879fbe
commit e71a793a7b
2 changed files with 12 additions and 0 deletions

View File

@ -23,6 +23,11 @@
<version>3.2</version> <version>3.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -6,6 +6,7 @@ import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -19,9 +20,15 @@ public class MyMojo
@Parameter(property = "outputDirectory", defaultValue = "target") @Parameter(property = "outputDirectory", defaultValue = "target")
private File outputDirectory; private File outputDirectory;
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;
public void execute() public void execute()
throws MojoExecutionException { throws MojoExecutionException {
logger.info("Starting execution..."); logger.info("Starting execution...");
logger.info(String.format("My-mojo plugin running on %s:%s:%s",
project.getGroupId(), project.getArtifactId(), project.getVersion()));
File f = outputDirectory; File f = outputDirectory;
if (!f.exists()) { if (!f.exists()) {