InputChanges and SourceSetOutput

Following up on How to create SourceSetContainer? I could never figure out how to create a SourceSetContainer so I ended up just keeping track of the SourceSetOutputs I need[1]. I want to combine this with incremental task inputs. The trouble I am having is figuring out how to query the input changes for a particular SourceSetOutput directory.

	@Internal
	@SkipWhenEmpty
	@Incremental
	public SourceSetOutput getSources() {
		return sources;
	}

	@TaskAction
	public void enhanceClasses(InputChanges inputChanges) {
		for ( File classesDir : sources.getClassesDirs() ) {
			// does not like - presumably InputChanges only works 
			//     for the complete incremental property
			final Iterable<FileChange> fileChanges = inputChanges.getFileChanges( project.fileTree( classesDir ) );
				...
			}
	}

The use case is that I need to be able to determine the class name for each file as I process it from the InputChanges. Alternatives to achieve that are very welcome.

[1] For background this is a bytecode enhancement task and I need to process a SourceSetOutput to access the compiled classes.

Hi Steve,

When you want to use InputChanges, then the incremental property needs to be a file input. In your case, you probably want to annotate the output (getSources) )with @InputFiles @PathSensitive(RELATIVE). @SkipWhenEmpty should stay, though it already includes @Incremental, so you don’t need to repeat it.

Then you can query the changes by:

inputChanges.getFileChanges(getSources())

This will already give you all the changes in the outputs, so no need to create a file tree.

Does this work for your use-case?

Cheers,
Stefan

Ah, did not know about @PathSensitive(RELATIVE)… thanks!

I will play with it later today and see.

Thanks @Stefan_Wolf