Maven plugin demo

master
Tomasz Polgrabia 2024-10-22 23:30:20 +02:00
parent 34e397682b
commit 14a383a55f
8 changed files with 251 additions and 0 deletions

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>pl.polgrabia.demos</groupId>
<artifactId>plugin-demo1</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>plugin-demo1-core</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,22 @@
package pl.polgrabia.demos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PluginRunner {
private static final Logger logger = LoggerFactory.getLogger(PluginRunner.class);
private final PluginRunnerConfig config;
public PluginRunner(PluginRunnerConfig config) {
this.config = config;
}
public static void main(String[] args) {
new PluginRunner(new PluginRunnerConfig("1", "2"))
.execute();
}
public void execute() {
logger.info("Started runner id: {}, name: {}", config.id(), config.name());
}
}

View File

@ -0,0 +1,8 @@
package pl.polgrabia.demos;
public record PluginRunnerConfig(
String id,
String name
) {
}

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>pl.polgrabia.demos</groupId>
<artifactId>plugin-demo1</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>plugin-demo1-plugin</artifactId>
<packaging>maven-plugin</packaging>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>pl.polgrabia.demos</groupId>
<artifactId>plugin-demo1-core</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,48 @@
package pl.polgrabia.demos.mojos;
import ch.qos.logback.core.util.StringUtil;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import pl.polgrabia.demos.PluginRunner;
import pl.polgrabia.demos.PluginRunnerConfig;
@Mojo(name = "runner")
public class PluginRunnerMojo implements org.apache.maven.plugin.Mojo {
private Log log;
@Parameter(name = "id")
private String id;
@Parameter(name = "name")
private String name;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (StringUtil.isNullOrEmpty(id)) {
id = System.getProperty("maven.runner.id");
}
if (StringUtil.isNullOrEmpty(name)) {
name = System.getProperty("maven.runner.name");
}
new PluginRunner(new PluginRunnerConfig(
id,
name
))
.execute();
}
@Override
public void setLog(Log log) {
this.log = log;
}
@Override
public Log getLog() {
return log;
}
}

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>pl.polgrabia.demos</groupId>
<artifactId>plugin-demo1</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>plugin-demo1-prog</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.runner.id>id1</maven.runner.id>
<maven.runner.name>name1</maven.runner.name>
</properties>
<build>
<plugins>
<plugin>
<groupId>pl.polgrabia.demos</groupId>
<artifactId>plugin-demo1-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<!--
<configuration>
<id>${maven.runner.id}</id>
<name>${maven.runner.name}</name>
</configuration>
-->
<executions>
<execution>
<id>runner</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.polgrabia.demos</groupId>
<artifactId>plugin-demo1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>plugin-demo1-core</module>
<module>plugin-demo1-plugin</module>
<module>plugin-demo1-prog</module>
</modules>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>