Subproject copy task not copying files

I am having issues with a subproject copy task. Every time I run this it says build successful but doesn’t perform the copy operation correctly. When ran with debug mode it says:

Skipping task ‘:app:copy’ as it has no source files.

 buildscript {
  repositories {
    mavenCentral()
    jcenter()
  }

  dependencies {
    classpath 'org.ajoberstar:grgit:1.1.0'
  }    
}

//Load required plugins
plugins {
  id 'org.hidetake.ssh' version '1.1.3'
}

def extProperties = new Properties()
file("build.properties").withInputStream{
    extProperties.load(it);
}
println extProperties['domain_name']

//All Projects properties
allprojects {
  //Remote server properties
  remotes {
    webServer {
      host = extProperties['domain_name']
      user = 'ec2-user'
      identity = file(extProperties['ssh_key_file'])
    }
  }

  task grettings << { task -> println "I'm $task.project.name" }
}

subprojects {
  //Add sub projects properties
}

//Deploy app folder
project(':app') {

  task copy(type: Copy) {
     outputs.upToDateWhen { false }
    includeEmptyDirs = true
    def fromDir = 'services/website/app/'
    def toDir = 'dist/app/'

    println fromDir
    println toDir

    from fromDir
    into toDir
  }
}

Can any one review this code and let me know why it is not copying files? The source directory contains php, html and css files while the destination folder is a place from where I will upload it online.

Hi, @khattak,

In my understanding of your description, you want to copy files from the directory root-dir/services/website/app into the directory root-dir/app/dist/app, right?


In the context of project(':app'){} block, a directory name is evaluated as relative to root-dir/app directory.

So, this task definition is

  • copy from root-dir/app/services/website/app
  • copy into root-dir/app/dist/app

If you don’t have a directory root-dir/app/services/website/app, Gradle considers input file is empty so that task :app:copy is always UP-TO-DATE.


If your goal is the same as my understanding, please modify :app:copy task definition as

project (':app') {
  task copy(type: Copy) {
    includeEmptyDirs = true
    def fromDir = rootProject.file('service/website/app/') // the directory is root-dir/services/website/app
    def toDir = 'dist/app/' // the directory is root-dir/app/dist/app
    from fromDir
    into toDir
  }
}

If my understanding is different from your goal, please let me know.

2 Likes

You are right. Adding the rootProject.file in subproject solved my issue. I am now using this code with a minor update in your code.

project (':app') {
  task copy(type: Copy) {
    includeEmptyDirs = true
    def fromDir = rootProject.file('service/website/app/') // the directory is root-dir/services/website/app
    def toDir = rootProject.file('dist/app/') // the directory is root-dir/app/dist/app - Updated
    from fromDir
    into toDir
  }
}

Thank you for the help and quick solution.

I’m very happy, to hear that your task works fine :smile:

1 Like