自定义Maven插件:如何处理FileSet?

问题描述 投票:0回答:1

我正在开发我的自定义 Maven 插件。该插件应接收的参数之一是文件集。这是插件本身的片段:

@Parameter
private FileSet[] filesets;

它编译良好并执行一些预期的任务。我还可以看到,当我将这些内容放入 pom 中时,文件集字段会被填充:

<configuration>
    ...
    <filesets>
        <fileset dir="/">
            <include name="**/*.*"/>
        </fileset>
    </filesets>
</configuration>

但是在插件中我不知道如何迭代包含的文件。下面的代码总是给我一个空列表:

FileSetManager fileSetManager = new FileSetManager();
fileSetManager.getIncludedFiles(fileset);

沮丧的是,我更改了模式以包含文件系统中的所有文件 - 但仍然没有成功。有关该主题的文档仅涉及定义参数,并未详细说明如何使用它们:https://maven.apache.org/guides/plugin/guide-java-plugin-development.html#Parameters

那么如何正确迭代文件集中的文件?

编辑:如果有人认为我提供了模糊的信息 - 这与您在 Maven 插件开发指南中看到的一样多。看来还是有人能看懂的。

java maven maven-plugin
1个回答
0
投票

我找到了一些专门用于在 Maven 中处理文件集的附加文档: https://maven.apache.org/shared/file-management/examples/mojo.html

虽然这确认我位于正确的路径上,但仍然没有导入文件。我将其深入到配置中。它需要看起来像这样:

<configuration>
    ...
    <filesets>
        <fileset>
            <directory>/</directory>
            <include name="**/*.*"/>
        </fileset>
    </filesets>
</configuration>

注意

directory
元素!

© www.soinside.com 2019 - 2024. All rights reserved.