Custom processResources task


(Kevin Peter) #1

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'
}

(Schalk Cronjé) #2

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).


(Kevin Peter) #3

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’
}
}


(Schalk Cronjé) #4

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.


(Kevin Peter) #5

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


(Schalk Cronjé) #6

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.


(Kevin Peter) #7

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’
}
}


(Schalk Cronjé) #8

You probably need **/*.properties.


(Schalk Cronjé) #9

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 *****'
}

(davidmichaelkarr) #10

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

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

(Schalk Cronjé) #11

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