You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Damon Jacobsen <da...@codedragon.us> on 2018/04/25 22:55:52 UTC

custom maven plugin howto

I am trying to get my feet wet with plugin development, and struggling with
some of the basics.I am trying to get the resource I am copying into the
build directory to be filtered in the same way that the maven resources
plugin works. I could manually filter for only my own properties, but I
would like to filter everything in the same way the resources plugin does.


I have a basic project folder set up as such:

src
--main
----resources
------test.txt
----java
------Main.java
pom.xml

Main looks like

@Mojo(name = "build", defaultPhase = LifecyclePhase.INSTALL,
requiresProject = true)
public class MyMojo
        extends AbstractMojo
{
    @Parameter(property = "my.property", required = true)
    private File myProperty;

    @Parameter(property = "project.build.directory", required = true)
    private File outputDirectory;

    public void execute()
            throws MojoExecutionException
    {
        try {
            InputStream systemResourceAsStream =
this.getClass().getResourceAsStream("test.txt");
            Files.copy(systemResourceAsStream,
f.toPath().resolve("test.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}


pom.xml is that which generated from the archetype.

I tried looking at online examples, but I cannot seem to find anything
between very basic, and very complex examples.

Thank you for any assistance,
Damon