Delete file in ant

To simplify access, I have several configuration files in the parent row of the project folders. When creating projects, they must be copied to one of the source folders of the projects before the assembly is completed, after which I want them to be deleted. At the moment, I have the following:

<target name="build-java"> <copy file="config.properties" todir="project/src" /> <!-- Build other projects --> <delete file="project/src/config.properties" /> </target> 

What kind of work the project does. Alas, for my pride, they are not always. Ideally, I would like to get the equivalent of the following Java:

 File src = new File("config.properties"); File dst = FileUtils.copyFile(src, "project/src"); dst.deleteOnExit(); // Carry on with the rest of the build, content in the knowledge that whatever happens, the file will die. 

But neither Copy nor Delete ant tasks seem suitable for work. Doesn't this seem like a particularly obscure need?

+4
source share
2 answers

You can try ant -contrib trycatch to run the uninstall task, even if the assembly failed.

There are other goodies in ant -contrib as a foreach task. If you can install it.

+3
source

How to define a β€œclean” task that deletes the remaining files, and you can call it after each build (even after failed builds)?

I think that Ant does not do very well with these kinds of conditional flow control. There may be a way to make this work, but it can get messy,

+4
source

Source: https://habr.com/ru/post/1300392/


All Articles