在Maven插件中设置Mojos和参数的描述

问题描述

我正在编写一个maven插件,我想添加一些有关可用目标和参数的文档。

当我运行mvn help:describe -Dplugin=myplugin -Ddetail时,它会打印出可用的目标和参数。但是它无处不在(没有描述)。通过搜索互联网,我不知道要在哪里设置这样的描述。

作为参考,我的插件是用scala编写的,看起来大致像这样。

import org.apache.maven.plugins.annotations.{ Component,Parameter }


class MyMojo extends AbstractMojo {

 @Parameter(defaultValue = "false",readonly = false)
 private var skipFormatting: Boolean = _

}

所以我的问题是:在哪里可以设置描述,使其以mvn help:describe -Dplugin=myplugin出现?

解决方法

我强烈建议使用以下内容:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.6.0</version>
    <executions>
      <execution>
        <id>default-descriptor</id>
        <phase>process-classes</phase>
      </execution>
      <execution>
        <id>generate-helpmojo</id>
        <goals>
          <goal>helpmojo</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

,它将在构建过程中生成帮助部分。是的,您必须添加一些像这样的javadoc:

@Mojo(name = "failure",defaultPhase = LifecyclePhase.NONE,requiresDependencyResolution = ResolutionScope.NONE,threadSafe = true)
public class FailureMojo extends AbstractMojo {

我不明白为什么您的Mojo上没有任何注释?

像这样的文档:https://maven.apache.org/plugins/maven-install-plugin/plugin-info.html将从参数等的javadoc生成。https://github.com/apache/maven-install-plugin/blob/master/src/main/java/org/apache/maven/plugins/install/InstallMojo.java#L69

,

根据在help:describe等熟悉的插件上运行maven-jar-plugin的示例,tt似乎基于Mojo类的Javadoc。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...