admin管理员组

文章数量:1200364

I want to verify if my Gradle build file has specific properties. For example, certain tasks are enabled, and specific plugins are present. Is there a recommended way to write such test?

I want to verify if my Gradle build file has specific properties. For example, certain tasks are enabled, and specific plugins are present. Is there a recommended way to write such test?

Share Improve this question asked Jan 22 at 12:39 pixelpixel 26.4k39 gold badges166 silver badges283 bronze badges 1
  • 1 I've done similar things to check for preconditions on my build by creating a custom task and fail the build if the precondition is not met. Not sure this would fit your requirement though. – Augusto Commented Jan 22 at 13:45
Add a comment  | 

1 Answer 1

Reset to default 1

Extract any meaningful code from your build file into a plugin and test the plugin within a sample Gradle project that applies that plugin. There you can make whatever assertions you like with the sample project.

Gradle provide instructions on writing plugins plus a suite of tools for testing plugins.

Additionally, if there is any code that it doesn't make sense to extract into a plugin you could make runtime assertions at the end of the build (probably within a Project.afterEvaluate() hook) so that it will fail fast in the event any expected conditions are not met.

本文标签: unit testingHow to write a test for buildgradlektsStack Overflow