title: gradle:how to run task in a method
body: <p>i want run a task in a method or function,how to write code,can you give me a demo?
  thanks.</p>
  
  <p>for example ...</p>
  
  <p>this is a task.</p>
  
  <pre><code>task releaseJar(type: Copy) {
      from('build/intermediates/bundles/release')
      into('build/output/jar')
      include('classes.jar')
      rename('calsses.jar', 'core' + '0.0.1' + '.jar')
  }
  </code></pre>
  
  <p>i want run it in </p>
  
  <pre><code>artifacts {
     ...same as  call releaseJar
      def myreleasejar = file 'build/output/jar/core0.0.1.jar'
      archives myreleasejar
      archives sourcesJar
  }
  </code></pre>