Custom processResources task

Hi,

I have added processResources to include all property files WITH ITS FOLDER STRUCTURE inside the gradle build as below. But how can I make sure this “processResources” getting invoked ONLY with gradle build. Because I have other custom tasks (like copyTask) to create some local setup. When I am invoking my other custom tasks, this processResources is also getting invoked.

processResources {
  from ('src/main/java') {
    include '**/\*.properties'
  }
}

Below is snippet from another custom task

task copyTask << {
   println 'TcopyTask'
}

This should not happen, unless you have some form of dependencies between tasks (either direct via dependsOn or indirect via depending on output of another task).

Kindly find below my build.gradle below. When I am invoking “gradle localConfi”, the “processResources” is getting invoked.

apply plugin: ‘java’

repositories {
mavenCentral()
}

task localConfig << {
println 'Task ***** localConfig ***** '
}

processResources {
println 'Task ***** processResources*****'
from (‘src/main/java’) {
include ‘**/*.properties’
}
}

Do think it is being run because you are seeing output like this?

Task ***** processResources*****
:localConfig
Task ***** localConfig ***** 

If it is, then processResources is not being executed, merely configured.

Yes. Because I am seeing the output like this. I thought it is getting executed.

Not too worry: you made a common mistake; confusing configuration with execution.

If you do

processResources << {
  println 'Task ***** processResources*****'
}

which will append that action to the end of the processResources actions, you’ll see that it only get’s executed when build the project.

I tried it with <<. But I don’t see the .property files are getting copied after the build. It is creating the directory structure in resources folder. Below is the complete task.

processResources << {
println ‘Task ***** wallet-job processResources ***'
from (‘src/main/java’) {
include '
/*.properties’
}
}

You probably need **/*.properties.

Oh duh, I see what you typed. You need to do the following:

// This is configuring the task
processResources << {
    from ('src/main/java') {
    include '**/*.properties'
  }
}

// This is appending an action to the task
processResources << {
    println 'Task ***** wallet-job processResources *****'
}
1 Like

Seems like there are several problems here. Would this be what he needs?

  from('src/main/java') {
    include ('**/*.properties')
  }
  doLast {
    println 'Task ...'
  }
}```
1 Like

LOL. Just as I posted, your post appeared. And yes, ’doLast is an alternative to te << in this case.

1 Like