Task ordering problems when using pathing jars

I had a “classpath too long” error on Windows, which I could solve using a pathing jar. That is, I create a new jar, put the runtime configuration file paths into the Class-Path attribute in its manifest file, and I only use this new jar on the classpath for a JavaExec task.

It works fine and all classes can be found, but this solution does not guarantee that the used project jars are actually created. If I execute a “clean build”, I do get ClassNotFound exceptions. It seems that Gradle can infer which subprojects need to be built first, if I use the JavaExec solution, where the classpath property is simply set to a specific configuration.

dependencies {
 compile project(':someotherproject')
 // many other project and lib dependencies...
}
  task someExecTask(type: JavaExec){
 classpath = configurations.runtime
 main = 'some.MainClass'
}

But if I use the pathing jar then the main class can be missing:

project.task('pathingJar', type: Jar) {
 classifier 'pathing'
 doFirst {
  manifest {
   // uri is just needed for Windows-compatibility
   attributes 'Class-Path': configurations.runtime.files.collect{ project.uri(it) }.join(' ')
  }
 }
}
  task someExecTask(type: JavaExec){
 dependsOn pathingJar
 classpath = files(pathingJar.archivePath)
 main = 'some.MainClass' // this class may not be found, it is coming from another project
}

The problem is that the pathingJar runs earlier than the jar task of the project that compiles the relevant main class. But this information was infered somehow when using the immediate classpath setting.

My question is: how can I tell Gradle to build these projects first without explicitly listing all projects by hand. I tried to use an explicit dependsOn relation, but I am not sure if I can use a fileset in dependsOn:

task someExecTask(type: JavaExec){
 dependsOn pathingJar
 dependsOn configuration.runtime
 classpath = files(pathingJar.archivePath)
 main = 'some.MainClass' // this class may not be found
}

And it also seems to result in misterious fails sometimes. Is there a better way to fix the task ordering issue here?

Thanks in advance!

You need to make ‘pathingJar’ ‘dependsOn’ ‘configurations.runtime’. While it doesn’t use the actual files, it’s still dependent on it for the value of the manifest attribute.