【问题标题】:Gradle protobuf custom taskGradle protobuf 自定义任务
【发布时间】:2015-11-10 21:29:41
【问题描述】:

鉴于此 protobuf gradle 配置:

当我们执行generateProto任务(由protobuf插件生成)时,我们将得到以下输出:

如您所见,自定义任务cleanProtogenerateProto 之前执行。

如果我没有定义这些任务之间的依赖关系,为什么它会执行?

【问题讨论】:

  • 你使用的是哪个 protobuf 插件?
  • com.google.protobuf:protobuf-gradle-plugin:0.7.0 但似乎我定义了错误的任务,当我将任务定义更改为 "task(cleanProto)

标签: gradle protocol-buffers


【解决方案1】:

实际上..它根本没有执行。 println 语句在配置 阶段执行,而不是在执行 阶段。要验证它,请将cleanProto 更改为:

task cleanProto << {
   println 'deleting gen'
   delete 'gen'
}

现在,如果没有定义依赖项,它根本不会执行。使用&lt;&lt; 添加一个动作。动作在执行阶段运行。

也请查看this 的回答。

附:下次不要提供代码的图像,而是复制并粘贴它。您可以在 Mac 上使用 cmd+k 组合。

【讨论】:

  • 哦,当然,我马上就接受了,但它有 5 分钟的限制,然后我忘记了:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-01
  • 2015-06-14
  • 1970-01-01
  • 2019-06-07
  • 2015-12-30
  • 1970-01-01
相关资源
最近更新 更多