Android 如何添加';选项';到gradlew帮助--任务文档

Android 如何添加';选项';到gradlew帮助--任务文档,android,gradle,documentation,version,task,Android,Gradle,Documentation,Version,Task,我的build.gradle文件中有以下设置: // Task designed to bump version numbers. This should be the first task run // after a new release branch is created. task bumpVersion(description: 'Bumps the version number of the c

我的
build.gradle
文件中有以下设置:

// Task designed to bump version numbers. This should be the first task run     
// after a new release branch is created.                                       
task bumpVersion(description: 'Bumps the version number of the current Android release. Should be used as a standalone task, and should only be the first task called after creating a release branch.', group: 'Management') << {
  Properties props = new Properties();                                          
  File propsFile = new File('gradle.properties');                               
  props.load(propsFile.newDataInputStream());                                   
  def currentVersionCode = props.getProperty("CORE_VERSION_CODE") as int;       
  def currentVersionName = props.getProperty("CORE_VERSION_NAME") as String;    
  def intPortionsOfVersionName = currentVersionName.tokenize('.').toArray();    
  def leastSignificantPortion = intPortionsOfVersionName[intPortionsOfVersionName.length - 1] as int;

  def newVersionCode = currentVersionCode + 1;                                  
  def newVersionName = "";                                                      
  if (!project.hasProperty('newVersion')) {                                     
    leastSignificantPortion = leastSignificantPortion + 1;                      
    intPortionsOfVersionName[intPortionsOfVersionName.length - 1] = leastSignificantPortion;
    newVersionName = intPortionsOfVersionName.collect{ it }.join(".");          
  } else {                                                                      
    newVersionName = project.getProperty('newVersion');                         
  }                                                                             

  props.setProperty("CORE_VERSION_NAME", newVersionName as String);             
  props.setProperty("CORE_VERSION_CODE", newVersionCode as String);             

  props.store(propsFile.newWriter(), null);                                     
}

请注意选项部分下的“--task”是如何显示的。我想知道如何用我自己的代码来实现这一点

这可以使用
@选项
注释来完成

@Option(option = "version", description = "Version number to use")
public void setVersion(String version) { ... }
注意:这是一个内部API,因此可能会更改


编辑:可能忘了提及您必须执行任务以利用此功能。

Hm,因此我刚刚意识到我只能通过
-D
-p
在命令行上指定参数。这是次优的,因为我希望能够运行
gradle bumpVersion--name
。因此,看起来这在外部任务中可能是不可能的?那么,我是否要将
@选项
注释添加到我的自定义任务声明中?我不知道如何将它与自定义任务类结合使用。你能给出一个更全面的代码示例吗?是的,请看一下任务。啊,太好了。非常感谢。
@Option(option = "version", description = "Version number to use")
public void setVersion(String version) { ... }