Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 601095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:40:38+00:00 2026-05-13T16:40:38+00:00

In the code presented here: Gant file , there is the following code: target(dist:

  • 0

In the code presented here: Gant file, there is the following code:

target(dist: 'Create release artefacts') {
        depends(test)
        depends(jar)
}
target(run: 'Run the distributed jar') {
        depends(dist)
        Ant.java(jar: distributedJarPath, fork: 'true')
}

target(hello: 'Hello World') {
        println("Hello World")
}

setDefaultTarget(dist)

I’m interested in how it’s able to write setDefaultTarget(dist), and not receive an exception about dist as a missing property. Is this snippet evaluated in the context of some object, and the targets create instance variables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:40:39+00:00Added an answer on May 13, 2026 at 4:40 pm

    There are two items you need to consider, the Binding of the script, and how a target is declared.

    First there is the binding. A Groovy script is a bit different from a Groovy/Java class. Groovy scripts allow for unbound variables. Meaning when you compile the script the variable need not be declared. When the compiler sees one of these undeclared variable references, it will convert the refrence to the variable under the covers to a call to binding.getVariable(variable name) (or something thereabout). So the last line of the script is functionally equivilant to

    setDefaultTarget(binding.getVariable('dist'))
    

    Second there is the is the declaration of the target. When the target is declared the Groovy compiler is actually seeing a method call: target(Map args, Closure closure) (or thereabout). When this method executes it examines the args, extracts the name of the target, and stores some wrapped reference to the closure by that name in the binding. An appropximation would be..

    target(Map args, Closure closure) {
      binding.setVarialbe( 
        args.keySet().iterator().next(),
        gantClosureWrapping(args, closure))
    }
    

    Of course the above code is an approximation and not the real gant code.

    so in essence…

    target(dist: 'doc') { ... }
    // the above adds 'dist' as a variable to the binding
    
    //...
    
    setDefaultTarget(dist)
    // dist is unbound, so it is replaced with binding.getVariable('dist')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 289k
  • Answers 289k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As you have root access, try looking for what is… May 13, 2026 at 5:38 pm
  • Editorial Team
    Editorial Team added an answer If you don't know whether it was allocated with new… May 13, 2026 at 5:38 pm
  • Editorial Team
    Editorial Team added an answer Place the variable you need into the "value" field of… May 13, 2026 at 5:37 pm

Related Questions

I have an unsorted dictionary file named dict.txt. I have managed to put the
When trying to use the code presented here link text I ran into some
I encountered a problem when running some old code that was handed down to
In this question a code bit is presented and the questioner wants to make
Edit: On further examination Firefox does not seem to be doing this, but Chrome

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.