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 8369053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:32:52+00:00 2026-06-09T13:32:52+00:00

In my Gradle build, I want to define a reusable function for copying files

  • 0

In my Gradle build, I want to define a reusable function for copying files to a remote host. Inside the function I want to use the scp Ant task. The code below works:

def remoteCopy(todir) {
    ant.scp(
            todir: todir,
            passphrase: XXXXXXXX,
            keyfile: XXXXXXXX) {
        fileset(dir: 'config') {           // I want this to be passed
            include(name: '**/*.txt')      // in as a parameter to the
        }                                  // function
    }
}

task example {
    remoteCopy('user@host:/home/xxxxxxx/')
}

However, I don’t want to hardcode the fileset(s) inside the remoteCopy function. I want to be able to call the function something like this (if this syntax is possible):

remoteCopy('user@host:/home/xxxxxxx/') {
    ant.fileset(dir: 'config') {
       include(name: '**/*.txt')
    }
}

Or perhaps as a second parameter:

remoteCopy('user@host:/home/xxxxxxx/',
    ant.fileset(dir: 'config') { include(name: '**/*.txt') } )

Can someone who knows Groovy and/or Gradle help?


For the sake of completeness, to make it easier to reproduce, this is how I am initializing the scp Ant task within my Gradle script:

configurations { ant_jsch }

repositories { mavenCentral() }

dependencies { ant_jsch 'org.apache.ant:ant-jsch:1.8.1' }

ant.taskdef(name: 'scp',
    classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp',
    classpath: configurations.ant_jsch.asPath)
  • 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-06-09T13:32:54+00:00Added an answer on June 9, 2026 at 1:32 pm

    Does this work?

    def remoteCopy( todir, Closure fset ) {
      ant.scp( todir: todir, passphrase: XXXXXXXX, keyfile: XXXXXXXX) {
        fset()
      }
    }
    
    remoteCopy( 'user@host:/home/xxxxxxx/' ) {
      ant.fileset( dir: 'config' ) {
        include( name: '**/*.txt' )
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Gradle outputs all the build sub-project generated files into buildSrc/build - I don't want
I want to use gradle's CreateStartScripts Task to generate the script to start the
I want to add a PMD task to my gradle build, that would give
From my gradle build I want to minify my html as part of the
I'm having a duplicate files issue with my Gradle build script. My directory structure
I've got a build.gradle task that works like a champ on my dev box
I am running my next gradle-javadoc-doclet task: apply plugin: com.myproject.build.gradle.web.WebPlugin apply plugin: 'java' apply
I am trying to use the zip in gradle and my build worked fine
I build my project with Gradle 1.0 and I use the EMMA plugin for
I'm learning to use Gradle by putting together a few simple build scripts as

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.