title: Using groovy.transform.Field to define another Field
body: <p>I am writing a Groovy script, where I need to use some of my fields inside closures. Below is a very simplified example to demonstrate my problem.</p>
  
  <pre><code>#!/usr/bin/env groovy
  
  import groovy.transform.Field
  
  @Field def first = 'one'
  assert first == 'one'
  </code></pre>
  
  <p>So far so good. In my real-world case, this will hold a String representing a server name. I then modify this "default" value from command-line options - using CliBuilder() - maybe something like:</p>
  
  <pre><code>first = 'two'
  assert first == 'two'
  </code></pre>
  
  <p>This still works. I now need to create a new field, from the one above:</p>
  
  <pre><code>@Field def second = first
  assert second == 'two'
  </code></pre>
  
  <p>In my real-world case, this will be an HTTPBuilder() that I will be making REST calls with.</p>
  
  <p>This fails:</p>
  
  <pre><code>Assertion failed: 
  
  assert second == 'two'
         |      |
         'one'  false
  </code></pre>
  
  <p>Is there a way to get this to work?</p>
  
  <p>A failed attempt to somehow work around this. Using an intermediary, something like:</p>
  
  <pre><code>def intermediary = first
  assert intermediary == 'two'
  @Field def second = intermediary
  </code></pre>
  
  <p>Fails with:</p>
  
  <pre><code>Caught: java.lang.reflect.InvocationTargetException
  java.lang.reflect.InvocationTargetException
      at something.main(something)
  Caused by: groovy.lang.MissingPropertyException: No such property: intermediary for class: something
      at something.&lt;init&gt;(something)
      ... 1 more
  </code></pre>