问题描述
我正在编写一个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。