Any way to remove files from a task inputs?

I would need a way to remove files from a task inputs.

I’m creating a task with type: JavaExec: this type of task seems to consider any file passed as an arg as a task input. This is quite smart, but in my case one of the arg is actually an OUTPUT, not an input. I’ve added it to the task outputs, but since it’s also considered by Gradle a task input, I cannot make the up-to-date mechanism work appropriately (since at any execution the output file contents change).

The problem is I can’t find any way to remove files from the task inputs: neither TaskInputs API seems to allow this, nor the FileCollection I can get from task.inputs.files does. I can’t even do: task.inputs.files -= task-outputs.files because task.inputs.files is a read-only property.

The only workaround I can think of is to rewrite my task as a generic task and use Project.javaExec(…) for execution. Any help/suggestion would be really appreciated.

That doesn’t sound quite right.

What leads you to believe that file args are marked as inputs? I can’t find anything in the code that does this.

Well, I actually discovered that it was not due to the args that some of the outputs fell in the inputs, but it was due to the way the classpath was built. It’s hard to explain the whole use case, however I fixed this.

What I’m still missing is the possibility to remove elements from the task inputs.

There’s no way to remove items from the inputs. Making this possible would cause complications elsewhere, and we haven’t found a compelling enough use case to justify the complication.

Can you share some more about your use case?

Right now I’ve solved my problem, so my use case is not significant anymore. However I find it quite limitating to be able to add files but not to remove them from the inputs. Thanks anyway for your help.

i’m stuck with similar problem. I’m declaring some dynamic gwt tasks and somehow they all get (or inherit in some way) inputs like ‘src/main/java’ and ‘src/main/resources’. Obviously this it not desired, because gwt module would be rebuilt every time something changes in these folders. I descared task inputs/outputs but i’m not able to remove this ‘‘default’’ input.

gradle build file and some additional info (output of ‘taskInfo’ task):

thanks in advance

Same problem here. I have a Multi-Project and I generate one file (ibm-ejb-jar-bnd.xml) with JavaExec. So input = *.java ( and output = buildDir/WEB-INF/ibm-ejb-jar-bnd.xml Here ist my task

  task createIbmJarBndXML(type: JavaExec) {

inputs.files fileTree(project.buildDir.absolutePath + '/../').include('src/main/java/com/company/**/*.java').include('src/main/java/de/company/**/*.java')

outputs.files file(project.buildDir.absolutePath + '/WEB-INF/ibm-ejb-jar-bnd.xml')

main = ''

classpath = sourceSets.main.runtimeClasspath

 args project.buildDir.absolutePath, project.buildDir.absolutePath + '/WEB-INF'  }  

Problem 1 with

inputs.files = sourceSets.main.allJava
==> The output file (ibm-ejb-jar-bnd.xml) is used for input Q1: allJava is documented as all Java Files, but *.xml is not a java file

Problem 2 with

inputs.files = fileTree(project.buildDir.absolutePath + ‘/…/’).include(‘src/main/java/com/company//*.java’).include('src/main/java/de/company//*.java’)  

Input file Y:\5100_Code_Base\Workspace\AppService\build\resources\main\META-INF\ibm-ejb-jar-bnd.xml has been added. Q2: with *.java I really mean only *.java. Why is that file added to input?

Thanks for any hints

be aware that everything from task’s ‘classpath’ goes to inputs as well

Thank you Daniil Bubnov, that seems to be the problem. Is that documented? Where? If not, it should be. I’ve problems with modifing the classpath of the javaExec task I want to exclude the resource-folders, I tried this:

 def cpOrig = sourceSets.main.runtimeClasspath.getFiles();

 def cp = sourceSets.main.runtimeClasspath.getFiles();

  cpOrig.each{f ->

 if (f.absolutePath.endsWith('build\\resources\\main')) {

println 'removing ' + f.absolutePath


 } else {

println 'keeping ' + f.absolutePath



main = '...'

classpath = files(cp)  

This works: classpath = sourceSets.main.runtimeClasspath

How can I remove the build/resources/main from the runtimeClasspath?