i have a project that uses a parent ant file
similar to this:
<project name="some-portlet" basedir="." default="deploy">
<import file="../build-common-portlet.xml" />
<target name="test">
<echo message="do foo"/>
RUN TEST FROM PARENT HERE
</target>
</project>
now i want to override the parent test target in this way:
the first part is no problem, but i do not see a way to call test from the parent file
i want the target to be named test also, so that CI can simply run the test target.
is there a way to call test in ../build-common-portlet.xml ?
Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it. This way: Anything set at the command line takes precedence over build.
To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.
When a target is invoked by antcall , all of its dependent targets will also be called within the context of any new parameters. For example. if the target doSomethingElse ; depended on the target init , then the antcall of doSomethingElse will call init during the call.
The simplest way is to use dependency on parent's test.
For that it's important that you keep <project>
name attribute in sync with its file name ( OK that's not, strictly speaking, necessary, but greatly improves your script's readability and maintainability ).
So in build-common-portlet.xml:
<project name="build-common-portlet" <-- note the name ... > <target name="test"> <echo message="Calling parent test target"/> ... </target> </project>
That way you can just do:
<project name="some-portlet" basedir="." default="deploy"> <import file="../build-common-portlet.xml" /> <target name="test" depends="build-common-portlet.test" <-- note parent specification > <echo message="do foo"/> RUN TEST FROM PARENT HERE </target> </project>
>> In reply to comment
If you want to do some work before running parent's test, just create a new target and put dependency on it before parent's test:
<project name="some-portlet" basedir="." default="deploy"> <import file="../build-common-portlet.xml" /> <target name="copy-jars"> <echo message="copying jars"/> </target> <target name="test" depends=" copy-jars, build-common-portlet.test " /> </project>
I found a solution, that would run my commands and then call test from the parent ant file. Override the parent's test, then call when the parent's test once you've done your own "magic".
All other parent's targets can be called too.
So for somebody not knowing your ant file, she can call ant test the way it's expected.
<project name="some-portlet" basedir="." default="deploy">
<import file="../build-common-portlet.xml" />
<target name="test">
<echo message="do foo"/>
<ant antfile="../build-common-portlet.xml" target="test"/>
</target>
</project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With