You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by broken connection <br...@gmail.com> on 2007/11/12 18:32:56 UTC

Question about "depends" attribute in the target element

Hi Friends,
As far as I knew, if we have "depends" in the target then that target
would run only once. But my target is running multiple times.

For example, I have this:

<target name="targetA">
</target>

<target name="targetB" depends="targetA">
</target>

The execution results as:
targetA
targetA
targetB

But I thought since "targetA" has already been executed it should show up as:

targetA
targetB

And only if targetA has not been executed before, then "targetB"
should execute "targetA" i.e again the same output

targetA
targetB

Please help me guys as to where my understanding is wrong.

Thanks
Mick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Question about "depends" attribute in the target element

Posted by broken connection <br...@gmail.com>.
Thanks Guys,
Actually i was trying to avoid that conditional looping and trying to set up
new variables just to control the execution of the targets.

Moreover, I think the "unless" should accept the target name to avoid
setting an explicit property eg:

<target name = "first" />
<target name="second" unless="first" />

Anyways, thanks for all your help and time guys...appreciate it.
Mick

On 11/12/07, glenn opdycke-hansen <gl...@gmail.com> wrote:
>
> Perhaps the ant code could create/touch a file at the conclusion of A and
> test if the file is created at the beginning of A.  If the file does not
> exist at the start of A, then invoke to actions of A.  If the file exists
> at
> the start of A then do not invoke the actions of A.
> A should be refactored to different targets:  testA and actionA.
>
> --glenn
>
> On Nov 12, 2007 1:10 PM, broken connection <br...@gmail.com>
> wrote:
>
> > Yeah,I apologize for that....but how can i resolve this guys???
> >
> > I want targetA and targetB to be indepently called under this scenario:
> > targetA can be called independently...
> > targetB always depends on targetA and should make sure targetA is ran
> > before
> > it runs....
> >
> > Any advice???
> >
> > Thanks
> >
> >
> > On 11/12/07, Rick Genter <rg...@silverlink.com> wrote:
> > >
> > > > From: broken connection [mailto: brokenconnection@gmail.com]
> > > > Sent: Monday, November 12, 2007 11:07 AM
> > > > To: Ant Users List
> > > > Subject: Re: Question about "depends" attribute in the target
> element
> > > >
> > > > Thanks Rick,
> > > > But like Glenn specified if you add an extra target then
> > > > everything works
> > > > fine, please see below:
> > >
> > > Yes, that's correct. There's nothing broken.
> > >
> > > If you do "ant first third" first will be run twice. Each target on
> the
> > > command line is invoked independent of the other targets on the
> command
> > > line.
> > >
> > > Ant is not make/gmake.
> > > --
> > > Rick Genter
> > > Principal Software Engineer
> > > Silverlink Communications
> > > rgenter@silverlink.com
> > > www.silverlink.com
> > > Office (781) 425-5763
> > > Mobile (781) 771-9677
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > > For additional commands, e-mail: user-help@ant.apache.org
> > >
> > >
> >
>

Re: Question about "depends" attribute in the target element

Posted by glenn opdycke-hansen <gl...@gmail.com>.
Perhaps the ant code could create/touch a file at the conclusion of A and
test if the file is created at the beginning of A.  If the file does not
exist at the start of A, then invoke to actions of A.  If the file exists at
the start of A then do not invoke the actions of A.
A should be refactored to different targets:  testA and actionA.

--glenn

On Nov 12, 2007 1:10 PM, broken connection <br...@gmail.com>
wrote:

> Yeah,I apologize for that....but how can i resolve this guys???
>
> I want targetA and targetB to be indepently called under this scenario:
> targetA can be called independently...
> targetB always depends on targetA and should make sure targetA is ran
> before
> it runs....
>
> Any advice???
>
> Thanks
>
>
> On 11/12/07, Rick Genter <rg...@silverlink.com> wrote:
> >
> > > From: broken connection [mailto:brokenconnection@gmail.com]
> > > Sent: Monday, November 12, 2007 11:07 AM
> > > To: Ant Users List
> > > Subject: Re: Question about "depends" attribute in the target element
> > >
> > > Thanks Rick,
> > > But like Glenn specified if you add an extra target then
> > > everything works
> > > fine, please see below:
> >
> > Yes, that's correct. There's nothing broken.
> >
> > If you do "ant first third" first will be run twice. Each target on the
> > command line is invoked independent of the other targets on the command
> > line.
> >
> > Ant is not make/gmake.
> > --
> > Rick Genter
> > Principal Software Engineer
> > Silverlink Communications
> > rgenter@silverlink.com
> > www.silverlink.com
> > Office (781) 425-5763
> > Mobile (781) 771-9677
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>

Re: Question about "depends" attribute in the target element

Posted by "Scot P. Floess" <fl...@mindspring.com>.
Set a property after you execute targetA - and then use an unless attribute

<target name = "targetA" unless "done">
    <property name = "done" value = "true"/>
...
</target>

<target name = "targetB" depends = "targetA">
...
</target>

broken connection wrote:
> Yeah,I apologize for that....but how can i resolve this guys???
>
> I want targetA and targetB to be indepently called under this scenario:
> targetA can be called independently...
> targetB always depends on targetA and should make sure targetA is ran before
> it runs....
>
> Any advice???
>
> Thanks
>
>
> On 11/12/07, Rick Genter <rg...@silverlink.com> wrote:
>   
>>> From: broken connection [mailto:brokenconnection@gmail.com]
>>> Sent: Monday, November 12, 2007 11:07 AM
>>> To: Ant Users List
>>> Subject: Re: Question about "depends" attribute in the target element
>>>
>>> Thanks Rick,
>>> But like Glenn specified if you add an extra target then
>>> everything works
>>> fine, please see below:
>>>       
>> Yes, that's correct. There's nothing broken.
>>
>> If you do "ant first third" first will be run twice. Each target on the
>> command line is invoked independent of the other targets on the command
>> line.
>>
>> Ant is not make/gmake.
>> --
>> Rick Genter
>> Principal Software Engineer
>> Silverlink Communications
>> rgenter@silverlink.com
>> www.silverlink.com
>> Office (781) 425-5763
>> Mobile (781) 771-9677
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>     
>
>   

-- 
Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate  http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim


RE: Question about "depends" attribute in the target element

Posted by Rick Genter <rg...@silverlink.com>.
> From: broken connection [mailto:brokenconnection@gmail.com] 
> Sent: Monday, November 12, 2007 11:11 AM
> To: Ant Users List
> Subject: Re: Question about "depends" attribute in the target element
> 
> Yeah,I apologize for that....but how can i resolve this guys???
> 
> I want targetA and targetB to be indepently called under this 
> scenario:
> targetA can be called independently...
> targetB always depends on targetA and should make sure 
> targetA is ran before
> it runs....
> 
> Any advice???

You'll need to structure your build something like this:

<target name="A" unless="A.has.already.run">
   <echo>I am target A</echo>
   <property name="A.has.already.run" value="true"/>
</target>

<target name="B" depends="A">
   <echo>I am target B</echo>
</target>

--
Rick Genter
Principal Software Engineer
Silverlink Communications
rgenter@silverlink.com
www.silverlink.com
Office (781) 425-5763
Mobile (781) 771-9677

This e-mail, including attachments, may include confidential and/or
proprietary information, and may only be used by the person or entity to
which it is addressed. If the reader of this e-mail is not the intended
recipient or his or her authorized agent, the reader is hereby notified
that any dissemination, distribution or copying of this e-mail is
prohibited. If you have received this e-mail in error, please notify the
sender by replying to this message and delete this e-mail immediately
 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Question about "depends" attribute in the target element

Posted by broken connection <br...@gmail.com>.
Yeah,I apologize for that....but how can i resolve this guys???

I want targetA and targetB to be indepently called under this scenario:
targetA can be called independently...
targetB always depends on targetA and should make sure targetA is ran before
it runs....

Any advice???

Thanks


On 11/12/07, Rick Genter <rg...@silverlink.com> wrote:
>
> > From: broken connection [mailto:brokenconnection@gmail.com]
> > Sent: Monday, November 12, 2007 11:07 AM
> > To: Ant Users List
> > Subject: Re: Question about "depends" attribute in the target element
> >
> > Thanks Rick,
> > But like Glenn specified if you add an extra target then
> > everything works
> > fine, please see below:
>
> Yes, that's correct. There's nothing broken.
>
> If you do "ant first third" first will be run twice. Each target on the
> command line is invoked independent of the other targets on the command
> line.
>
> Ant is not make/gmake.
> --
> Rick Genter
> Principal Software Engineer
> Silverlink Communications
> rgenter@silverlink.com
> www.silverlink.com
> Office (781) 425-5763
> Mobile (781) 771-9677
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

RE: Question about "depends" attribute in the target element

Posted by Rick Genter <rg...@silverlink.com>.
> From: broken connection [mailto:brokenconnection@gmail.com] 
> Sent: Monday, November 12, 2007 11:07 AM
> To: Ant Users List
> Subject: Re: Question about "depends" attribute in the target element
> 
> Thanks Rick,
> But like Glenn specified if you add an extra target then 
> everything works
> fine, please see below:

Yes, that's correct. There's nothing broken.

If you do "ant first third" first will be run twice. Each target on the
command line is invoked independent of the other targets on the command
line.

Ant is not make/gmake.
--
Rick Genter
Principal Software Engineer
Silverlink Communications
rgenter@silverlink.com
www.silverlink.com
Office (781) 425-5763
Mobile (781) 771-9677

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Question about "depends" attribute in the target element

Posted by broken connection <br...@gmail.com>.
Thanks Rick,
But like Glenn specified if you add an extra target then everything works
fine, please see below:

build.xml:

<project>
    <target name="first">
        <echo message="target First" />
    </target>

    <target name="second" depends="first">
        <echo message="target Second" />
    </target>

 <target name="third" depends="first,second">
        <echo message="target Third" />
    </target>
</project>
Output:

Total time: 0 seconds
C:\Documents and Settings\hjhutty\Desktop\test>ant first second
Buildfile: build.xml

first:
     [echo] target First

first:
     [echo] target First

second:
     [echo] target Second

BUILD SUCCESSFUL
Total time: 0 seconds
C:\Documents and Settings\mick\Desktop\test>ant third
Buildfile: build.xml

first:
     [echo] target First

second:
     [echo] target Second

third:
     [echo] target Third

BUILD SUCCESSFUL
Total time: 0 seconds
And I would like to know the solution for this, how to resolve this issue
then because I thought "depends" would do it for me but as you can see i am
getting stuck...

Thanks
Mick


On 11/12/07, Rick Genter <rg...@silverlink.com> wrote:
>
> > From: broken connection [mailto:brokenconnection@gmail.com]
> > Sent: Monday, November 12, 2007 11:01 AM
> > To: Ant Users List
> > Subject: Re: Question about "depends" attribute in the target element
> >
> > Thanks Glenn,
> > Here's a small test script that i wrote that simulates my
> > environment and
> > proves my findings:
> >
> > build.xml:
> > <project>
> >     <target name="first">
> >         <echo message="target First" />
> >     </target>
> >
> >     <target name="second" depends="first">
> >         <echo message="target Second" />
> >     </target>
> > </project>
> > Output:
> >
> > C:\Documents and Settings\mick\Desktop\test>ant first second
> > Buildfile: build.xml
> >
> > first:
> >      [echo] target First
> >
> > first:
> >      [echo] target First
> >
> > second:
> >      [echo] target Second
> >
> > BUILD SUCCESSFUL
> > Total time: 0 seconds
> > C:\Documents and Settings\hjhutty\Desktop\test>
> >
> > It clearly shows that the first target is run multiple
> > times.Can someone
> > please correct my understanding as to why this is happening.
>
> Ant targets specified on the command line are invoked independently;
> it's as if you specified "ant first ; ant second", with the caveat that
> any properties defined during the execution of the first target will
> still be defined when the second target is executed.
> --
> Rick Genter
> Principal Software Engineer
> Silverlink Communications
> rgenter@silverlink.com
> www.silverlink.com
> Office (781) 425-5763
> Mobile (781) 771-9677
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

RE: Question about "depends" attribute in the target element

Posted by Rick Genter <rg...@silverlink.com>.
> From: broken connection [mailto:brokenconnection@gmail.com] 
> Sent: Monday, November 12, 2007 11:01 AM
> To: Ant Users List
> Subject: Re: Question about "depends" attribute in the target element
> 
> Thanks Glenn,
> Here's a small test script that i wrote that simulates my 
> environment and
> proves my findings:
> 
> build.xml:
> <project>
>     <target name="first">
>         <echo message="target First" />
>     </target>
> 
>     <target name="second" depends="first">
>         <echo message="target Second" />
>     </target>
> </project>
> Output:
> 
> C:\Documents and Settings\mick\Desktop\test>ant first second
> Buildfile: build.xml
> 
> first:
>      [echo] target First
> 
> first:
>      [echo] target First
> 
> second:
>      [echo] target Second
> 
> BUILD SUCCESSFUL
> Total time: 0 seconds
> C:\Documents and Settings\hjhutty\Desktop\test>
> 
> It clearly shows that the first target is run multiple 
> times.Can someone
> please correct my understanding as to why this is happening.

Ant targets specified on the command line are invoked independently;
it's as if you specified "ant first ; ant second", with the caveat that
any properties defined during the execution of the first target will
still be defined when the second target is executed.
--
Rick Genter
Principal Software Engineer
Silverlink Communications
rgenter@silverlink.com
www.silverlink.com
Office (781) 425-5763
Mobile (781) 771-9677
 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Question about "depends" attribute in the target element

Posted by broken connection <br...@gmail.com>.
Thanks Glenn,
Here's a small test script that i wrote that simulates my environment and
proves my findings:

build.xml:
<project>
    <target name="first">
        <echo message="target First" />
    </target>

    <target name="second" depends="first">
        <echo message="target Second" />
    </target>
</project>
Output:

C:\Documents and Settings\mick\Desktop\test>ant first second
Buildfile: build.xml

first:
     [echo] target First

first:
     [echo] target First

second:
     [echo] target Second

BUILD SUCCESSFUL
Total time: 0 seconds
C:\Documents and Settings\hjhutty\Desktop\test>

It clearly shows that the first target is run multiple times.Can someone
please correct my understanding as to why this is happening.

Thanks
Mick

On 11/12/07, glenn opdycke-hansen <gl...@gmail.com> wrote:
>
> Could you post the complete Ant script?
> How are you invoking the script and the target(s)?
>
> I noticed if you invoke ant with both targetA and targetB, then targetA
> would be called multiple times.
>
> However if you invoke ant with targetC (below) then targetA is invoked
> once.
>
> <target name="targetC" depends="targetA, targetB">
> <echo>in targetC</echo>
> </target>
>
> --glenn
>
> On Nov 12, 2007 11:32 AM, broken connection <br...@gmail.com>
> wrote:
>
> > Hi Friends,
> > As far as I knew, if we have "depends" in the target then that target
> > would run only once. But my target is running multiple times.
> >
> > For example, I have this:
> >
> > <target name="targetA">
> > </target>
> >
> > <target name="targetB" depends="targetA">
> > </target>
> >
> > The execution results as:
> > targetA
> > targetA
> > targetB
> >
> > But I thought since "targetA" has already been executed it should show
> up
> > as:
> >
> > targetA
> > targetB
> >
> > And only if targetA has not been executed before, then "targetB"
> > should execute "targetA" i.e again the same output
> >
> > targetA
> > targetB
> >
> > Please help me guys as to where my understanding is wrong.
> >
> > Thanks
> > Mick
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>

Re: Question about "depends" attribute in the target element

Posted by glenn opdycke-hansen <gl...@gmail.com>.
Could you post the complete Ant script?
How are you invoking the script and the target(s)?

I noticed if you invoke ant with both targetA and targetB, then targetA
would be called multiple times.

However if you invoke ant with targetC (below) then targetA is invoked once.

<target name="targetC" depends="targetA, targetB">
<echo>in targetC</echo>
</target>

--glenn

On Nov 12, 2007 11:32 AM, broken connection <br...@gmail.com>
wrote:

> Hi Friends,
> As far as I knew, if we have "depends" in the target then that target
> would run only once. But my target is running multiple times.
>
> For example, I have this:
>
> <target name="targetA">
> </target>
>
> <target name="targetB" depends="targetA">
> </target>
>
> The execution results as:
> targetA
> targetA
> targetB
>
> But I thought since "targetA" has already been executed it should show up
> as:
>
> targetA
> targetB
>
> And only if targetA has not been executed before, then "targetB"
> should execute "targetA" i.e again the same output
>
> targetA
> targetB
>
> Please help me guys as to where my understanding is wrong.
>
> Thanks
> Mick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Re: Question about "depends" attribute in the target element

Posted by Matt Benson <gu...@yahoo.com>.
--- Steve Loughran <st...@apache.org> wrote:

> David Weintraub wrote:
> > If you invoke multiple targets on the command
> line, each target will
> > execute, and dependencies will execute
> independently. There is no way
> > of Ant to know if one of the targets you put on
> the command line might
> > affect a later target. For example:
> > 
> > $ ant first clean_first second
> > 
> > If Ant kept track of targets already executed, it
> would be messed up
> > by the "clean_first" target. Target "second"
> depends upon "first", but
> > "clean_first" destroyed what files "first" had
> built. That's why each
> > target will execute all of its dependencies.
> > 
> > However, this works fine:
> > 
> > <project name="test">
> > <target name="first"/>
> > <target name="second" depends="first"/>
> > <target name="third" depends="first,second"/>
> > </project>
> > 
> > Executing:
> > 
> > $ ant third
> > [first]
> > [second]
> > [third]
> > 
> > Executes target "first" only a single time
> 
> There is actually a way to maybe get Ant to resolve
> dependencies across 
> targets on the command line, but it isnt exposed to
> the end user. Inside 
> ant there are these things called Executors that
> decide which targets to 
> run next. The normal executor runs everything on the
> command line. If 
> you go -keepgoing, a new executor runs targets that
> dont depend on 
> targets that have failed; it 'keeps going' as well
> as it can. You could 
> probably add a new executor that took intra-target
> dependencies into 
> account, and switch to it using whichever magic
> property identifies the 
> new executor. This is pretty low level though; I
> don't know anyone who 
> has done this.
> 

This sounds suspiciously like the single-check
executor that runs command-line targets as if they
were all dependencies of another target, similar to
the example the user specified:

ant
-Dant.executor.class=org.apache.tools.ant.helper.SingleCheckExecutor
foo bar

HTH,
Matt

> -- 
> Steve Loughran                 
> http://www.1060.org/blogxter/publish/5
> Author: Ant in Action           http://antbook.org/
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> user-help@ant.apache.org
> 
> 



      ____________________________________________________________________________________
Get easy, one-click access to your favorites. 
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Question about "depends" attribute in the target element

Posted by Steve Loughran <st...@apache.org>.
David Weintraub wrote:
> If you invoke multiple targets on the command line, each target will
> execute, and dependencies will execute independently. There is no way
> of Ant to know if one of the targets you put on the command line might
> affect a later target. For example:
> 
> $ ant first clean_first second
> 
> If Ant kept track of targets already executed, it would be messed up
> by the "clean_first" target. Target "second" depends upon "first", but
> "clean_first" destroyed what files "first" had built. That's why each
> target will execute all of its dependencies.
> 
> However, this works fine:
> 
> <project name="test">
> <target name="first"/>
> <target name="second" depends="first"/>
> <target name="third" depends="first,second"/>
> </project>
> 
> Executing:
> 
> $ ant third
> [first]
> [second]
> [third]
> 
> Executes target "first" only a single time

There is actually a way to maybe get Ant to resolve dependencies across 
targets on the command line, but it isnt exposed to the end user. Inside 
ant there are these things called Executors that decide which targets to 
run next. The normal executor runs everything on the command line. If 
you go -keepgoing, a new executor runs targets that dont depend on 
targets that have failed; it 'keeps going' as well as it can. You could 
probably add a new executor that took intra-target dependencies into 
account, and switch to it using whichever magic property identifies the 
new executor. This is pretty low level though; I don't know anyone who 
has done this.

-- 
Steve Loughran                  http://www.1060.org/blogxter/publish/5
Author: Ant in Action           http://antbook.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Question about "depends" attribute in the target element

Posted by David Weintraub <qa...@gmail.com>.
If you invoke multiple targets on the command line, each target will
execute, and dependencies will execute independently. There is no way
of Ant to know if one of the targets you put on the command line might
affect a later target. For example:

$ ant first clean_first second

If Ant kept track of targets already executed, it would be messed up
by the "clean_first" target. Target "second" depends upon "first", but
"clean_first" destroyed what files "first" had built. That's why each
target will execute all of its dependencies.

However, this works fine:

<project name="test">
<target name="first"/>
<target name="second" depends="first"/>
<target name="third" depends="first,second"/>
</project>

Executing:

$ ant third
[first]
[second]
[third]

Executes target "first" only a single time

On Nov 12, 2007 12:32 PM, broken connection <br...@gmail.com> wrote:
> Hi Friends,
> As far as I knew, if we have "depends" in the target then that target
> would run only once. But my target is running multiple times.
>
> For example, I have this:
>
> <target name="targetA">
> </target>
>
> <target name="targetB" depends="targetA">
> </target>
>
> The execution results as:
> targetA
> targetA
> targetB
>
> But I thought since "targetA" has already been executed it should show up as:
>
> targetA
> targetB
>
> And only if targetA has not been executed before, then "targetB"
> should execute "targetA" i.e again the same output
>
> targetA
> targetB
>
> Please help me guys as to where my understanding is wrong.
>
> Thanks
> Mick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
--
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org