Using Gradle, how can I ensure that a file exists at a certain location?

Mendhak

I am starting to use Gradle for an Android application. I would like the build to fail if the developer fails to create a file at a specific location such as ./src/res/values/specialfile.xml

A bit of searching led me to believe that a .doFirst would work

android.doFirst { 
    assert file("./src/res/values/specialfile.txt").exists() 
} 

However, Gradle says "unsupported Gradle DSL method found: 'doFirst()'!"

What can I do to assert a file's existence?

Xavier Ducrohet

doFirst only exists on tasks object. android is not a task.

If would want this test to always be done even if the developer doesn't try to build (for example when running the tasks task), you should simply put in your build.gradle

assert file("./src/res/values/specialfile.txt").exists() 

However this is really not recommended as this would be executed even for non build tasks, or even when the model is built for IDE integration.

There is a task called preBuild that is executed before anything in the android build, so you can hook your test to it, either through another task or through doFirst:

preBuild.doFirst { 
    assert file("./src/res/values/specialfile.txt").exists() 
} 

本文收集自互联网,转载请注明来源。

如有侵权,请联系debugcn@gmail.com 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How can I send a string as NULL to SQLServer using Dapper?

来自分类Dev

How to parse a text file (CSV) into haskell so I can operate on it?

来自分类Dev

how can i switch web pages of the website automatically , which i have created, using javascript?

来自分类Dev

What Is a .vrc file, how is is generated and can you remove it using the IDE?

来自分类Dev

How can I get the x/y location of a touch relative to the entire view when I touch a button?

来自分类Dev

How can I stop controls from using a KeyEvent?

来自分类Dev

How can I get last inserted id using Hibernate

来自分类Dev

How can I change a word in a buffer using elisp?

来自分类Dev

How can I create a temporary table using PetaPoco?

来自分类Dev

How can I connect to a postgreSQL database into Apache Spark using scala?

来自分类Dev

How can I center text inside a div element using CSS

来自分类Dev

How do I print out just certain elements from a text file that has xml tags to a new text file?

来自分类Dev

How do I check if a certain User exists under a specific Login in SQL?

来自分类Dev

How can I stop myself from using 'git commit -a'?

来自分类Dev

Can I optionally Include specific file extensions with Wix Heat using transforms?

来自分类Dev

How can I read float data from a binary file using R

来自分类Dev

How can I work with a .csv file using Java Spring Resttample?

来自分类Dev

How can I get the current weekday in Rust using the Chrono crate?

来自分类Dev

How can I used ReadAllLines with gzipped file

来自分类Dev

How can i get from a FileInfo[] the file full name full directory including the file extension?

来自分类Dev

How can I print contents of file given filename as stdin in bash?

来自分类Dev

How can I loop through values in my json file?

来自分类Dev

How can I allow location access using Selenium?

来自分类Dev

How can I use sed to make thousands of substitutions in a file using a reference file?

来自分类Dev

how can i check a method in raw php, like oop method_exists()

来自分类Dev

How can I recursively find the *directories* containing a file of a certain type?

来自分类Dev

How to get user location city without using geo location

来自分类Dev

how to extract path from file location using shell

来自分类Dev

How can I find my browser web log file?

Related 相关文章

  1. 1

    How can I send a string as NULL to SQLServer using Dapper?

  2. 2

    How to parse a text file (CSV) into haskell so I can operate on it?

  3. 3

    how can i switch web pages of the website automatically , which i have created, using javascript?

  4. 4

    What Is a .vrc file, how is is generated and can you remove it using the IDE?

  5. 5

    How can I get the x/y location of a touch relative to the entire view when I touch a button?

  6. 6

    How can I stop controls from using a KeyEvent?

  7. 7

    How can I get last inserted id using Hibernate

  8. 8

    How can I change a word in a buffer using elisp?

  9. 9

    How can I create a temporary table using PetaPoco?

  10. 10

    How can I connect to a postgreSQL database into Apache Spark using scala?

  11. 11

    How can I center text inside a div element using CSS

  12. 12

    How do I print out just certain elements from a text file that has xml tags to a new text file?

  13. 13

    How do I check if a certain User exists under a specific Login in SQL?

  14. 14

    How can I stop myself from using 'git commit -a'?

  15. 15

    Can I optionally Include specific file extensions with Wix Heat using transforms?

  16. 16

    How can I read float data from a binary file using R

  17. 17

    How can I work with a .csv file using Java Spring Resttample?

  18. 18

    How can I get the current weekday in Rust using the Chrono crate?

  19. 19

    How can I used ReadAllLines with gzipped file

  20. 20

    How can i get from a FileInfo[] the file full name full directory including the file extension?

  21. 21

    How can I print contents of file given filename as stdin in bash?

  22. 22

    How can I loop through values in my json file?

  23. 23

    How can I allow location access using Selenium?

  24. 24

    How can I use sed to make thousands of substitutions in a file using a reference file?

  25. 25

    how can i check a method in raw php, like oop method_exists()

  26. 26

    How can I recursively find the *directories* containing a file of a certain type?

  27. 27

    How to get user location city without using geo location

  28. 28

    how to extract path from file location using shell

  29. 29

    How can I find my browser web log file?

热门标签

归档