Running a task only when dependencies are changed

In many projects, our classpath exceeds the 32k classpath restriction on Windows. To account for this we created an extra task that creates a jar with the actual classpath in the manifest. I only want to rerun this task when dependencies are changed, otherwise it triggers a full redeploy.

Here’s basically what I have:

  task('compileClasspathJar', type: Jar) {

doFirst {

 def relativeClasspathEntries = sourceSets.main.compileClasspath.collect {

  project.relativePath(new Path(it.getAbsolutePath()))

 }















  manifest {

  attributes "Class-Path": relativeClasspathEntries.join(" ")

 }

}  }

 task('setClassPathJar') {

dependsOn compileClasspathJar

doFirst {

 sourceSets.main.compileClasspath = files(new File(project.projectDir.getAbsolutePath(), 'compile-classpath.jar'))

}  }  

Is there anyway to connect dependencies to task inputs?

You should be able to set the source set compileClasspath as an input file collection:

task('compileClasspathJar', type: Jar) {
  inputs.files sourceSets.main.compileClasspath
  ...
}