How to make the final ant target execute regardless of dependencies

I have a basic ant script in which I copy a set of files to a directory for no purpose. Then I would like to clear these files after all / all goals have been launched regardless of dependencies. The main problem that I am facing is that the target can be “compiled” or “deployed”, so I cannot just blindly call the target “cleanUp” from “compilation”, because “deploywar” can be called as follows. And I cannot blindly call from "deploywar" because it cannot be called. How to determine the goal that will be called after the completion of all other necessary goals (unsuccessful or successful)? The goal of "cleanUpLib" below is the goal that I would like to call after / all completed tasks:

<project name="proto" basedir=".." default="deploywar"> ... <copy todir="${web.dir}/WEB-INF/lib"> <fileset dir="${web.dir}/WEB-INF/lib/common"/> </copy> <target name="compile"> <!-- Uses ${web.dir}/WEB-INF/lib --> .... </target> <target name="clean" description="Clean output directories"> <!-- Does not use ${web.dir}/WEB-INF/lib --> .... </target> <target name="deploywar" depends="compile"> <!-- Uses ${web.dir}/WEB-INF/lib --> .... </target> <target name="cleanUpLib"> <!-- Clean up temporary lib files. --> <delete> <fileset dir="${web.dir}/WEB-INF/lib"> <include name="*.jar"/> </fileset> </delete> </target> 
+4
source share
2 answers

To start the target after any / all goals, regardless of dependencies, you can use the assembly listener or the try / catch / finally template, for more details see:

+2
source

The solution for the build listener that Rebse points to looks useful (+1).

An alternative that you might consider would be to “overload” your goals, something like this:

 <project default="compile"> <target name="compile" depends="-compile, cleanUpLib" description="compile and cleanup"/> <target name="-compile"> <!-- your original compile target --> </target> <target name="deploywar" depends="-deploywar, cleanUpLib" description="deploywar and cleanup"/> <target name="-deploywar"> <!-- your original deploywar target --> </target> <target name="cleanUpLib"> </target> </project> 

Of course, you cannot overload Ant assemblies into a single file, so target names must be different.

(I used the “-” prefix above, which is a hacker to create “private” targets — that is, you cannot call them from the command line because of shell shell script processing. But, of course, you could double-click them successfully in Ant).

+2
source

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


All Articles