【问题标题】:Mojo plugin for writing to filesystem [closed]用于写入文件系统的 Mojo 插件 [关闭]
【发布时间】:2017-08-24 09:39:24
【问题描述】:

我想这样写mojo插件:

 /**
 * @goal write-to-fs
 */

public class WriteToFsMojo extends AbstractMojo
{

    public void execute() throws MojoExecutionException
    {
        String relativePathToFile = "resource/my_direcory/my_file.csv"
        // find `relativePathToFile` from where goal executes
        // write the file using goal arguments
    }
}

我想在项目特定文件中查找,例如Menu.csv 并将行从 mvn 目标参数插入到此文件中。

例如:

mvn org.apache.maven.plugins:my-plugin:write-to-fs "-Did=100" "-Dname=New Menu Item"

我感兴趣的是这种方法是否正确?可能吗?你能提供例子吗?

【问题讨论】:

    标签: java maven relative-path mojo


    【解决方案1】:

    首先,您使用的是使用 Javadoc doclet 注释类的古老方法。该机制已被弃用。从 Maven 3 开始,you should use annotations instead.

    除此之外,这取决于您在插件中尝试执行的操作。如果您详细说明您要做什么,我会扩展我的答案。

    这是一个骨架:

    @Mojo(name = "write-csv")
    public class WriteToFsMojo extends AbstractMojo {
    
        @Parameter(defaultValue = "${project}", readonly = true)
        private MavenProject project;
    
        @Parameter(property = "outputFile", defaultValue = "someFileName.csv")
        private String filePath;
    
        public void execute() throws MojoExecutionException {
            File outputFile = new File(project.getBasedir(), filePath);
            // now do something with it
        }
    }
    

    这将注入 Maven 项目定义,并让用户通过命令行或插件配置提供 outputFile 参数。

    【讨论】:

    • 肖恩·帕特里克,我已经更新了我的问题。
    猜你喜欢
    • 1970-01-01
    • 2015-03-20
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 2017-12-16
    相关资源
    最近更新 更多