@Classpath and up-to-date

I have the following task, which is never up-to-date:

@CacheableTask
public abstract class VerifyDependenciesTask extends DefaultTask {
	private final Property<Configuration> runtimeDependencies;

	...

	@Inject
	public VerifyDependenciesTask(ExtensionDescriptor config) {
		final JavaPluginExtension javaPluginExtension = getProject().getExtensions().getByType( JavaPluginExtension.class );
		final SourceSetContainer sourceSets = javaPluginExtension.getSourceSets();
		final SourceSet mainSourceSet = sourceSets.getByName( SourceSet.MAIN_SOURCE_SET_NAME );
		final ConfigurationContainer configurations = getProject().getConfigurations();

		runtimeDependencies = getProject().getObjects().property( Configuration.class );
		runtimeDependencies.set( configurations.getByName( mainSourceSet.getRuntimeClasspathConfigurationName() ) );
	}

	@Classpath
	public Provider<Configuration> getRuntimeDependencies() {
		return runtimeDependencies;
	}

	...
}

Am I using @Classpath incorrectly?

Does the task declare any outputs? If not, then it will never be up-to-date.

Thanks @Chris_Dore

That’s a bit disappointing. I have to create a completely useless output file just to get up-to-date checking to work. Well, useless outside of this Gradle requirement, anyway

No you don’t have to declare an output.
You just have to tell Gradle that it is ok to have no output and be up-to-date.
Just use outputs.upToDateWhen { true } and your task is able to be up-to-date without any actual outputs.

Btw. if you run with -i, Gradle tells you why a task is out of date like “no output defined”.

1 Like

And the task is still triggered when its inputs change? Wow, that would be perfect!

Exactly . . . . . . .

I was unaware the you could return true and get this behaviour. I was under the impression that returning true was effectively a NOP. Thanks for the info.