Maven не распознает параметры при запуске пользовательского mojo из CLI - PullRequest
1 голос
/ 20 марта 2020

Я пытаюсь запустить пользовательское mojo через командную строку (без файла pom)

mvn com.example.org:ei-mojos:1.0.073:apply-freemarker-template -DsrcDir=target -Dtemplate=createConfig.ftl -DoutputFile=config.json

Но я получаю сообщение об ошибке от Maven

 Failed to execute goal com.example.org:ei-mojos:1.0.175:apply-freemarker-template (default-cli) on project standalone-pom: The parameters 'outputFile', 'templateName', 'srcDir' for goal com.example.org:ei-mojos:1.0.175:apply-freemarker-template are missing or invalid -> [Help 1]

Вот фрагмент mojo

@Mojo(name = "apply-freemarker-template", requiresProject = false)
public class FreeMarkerMojo extends AbstractMojo {

    /**
     * The source directory containing the input files.
     */
    @Parameter(required = true, readonly = true)
    private File srcDir;

    /**
     * The template file to be processed.
     */
    @Parameter(alias = "template", required = true, readonly = true)
    private String templateName;

    /**
     * The location of the output file.
     */
    @Parameter(required = true, readonly = true)
    private File outputFile;

    /**
     * Data models to be used during template processing.
     */
    @Parameter(required = false, readonly = true)
    private HashMap<String, String> dataModels;

Возможно ли вызвать этот плагин из командной строки? Кроме того, как бы я go о указании параметра dataModels? Это выглядит так в пом. xml

<configuration>
   <template>createconfig.ftl</template>
   <outputFile>${project.build.directory}/config.json</outputFile>
   <dataModels>
      <abc>abc.json</abc>
      <def>def.json</def>
      <xxx>xxx.json</xxx>
   </dataModels>
</configuration>

1 Ответ

1 голос
/ 20 марта 2020

Параметры конфигурации и свойства Maven - это не одно и то же. Вам нужно сделать что-то вроде

@Mojo(name = "apply-freemarker-template", requiresProject = false)
public class FreeMarkerMojo extends AbstractMojo {

    /**
     * The source directory containing the input files.
     */
    @Parameter(required = true, readonly = true)
    private File srcDir;

    /**
     * The template file to be processed.
     */
    @Parameter(property="template", alias = "template", required = true, readonly = true)
    private String templateName;

    /**
     * The location of the output file.
     */
    @Parameter(property="outputFile", required = true, readonly = true)
    private File outputFile;

    /**
     * Data models to be used during template processing.
     */
    @Parameter(property="dataModels", required = false, readonly = true)
    private HashMap<String, String> dataModels;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...