Dean Hiller
Dean Hiller

Reputation: 20210

how to override a task making it depend on one of mine in gradle

I tried following the gradle manual with their example like this but copyJars is not run at all before the eclipse task. (the eclipse task comes from the eclipse plugin)

task('copyJars') { 

    ext.collection = files { genLibDir.listFiles() }
    delete ext.collection
    copy { from configurations.compile into genLibDir }
    copy { from fixedLibDir into genLibDir }
}

eclipse.dependsOn = copyJars

task('setupAll', dependsOn: 'eclipse') {
    description = 'Update jars from remote repositories and then fix eclipse classpath for stbldfiles project'
}

Upvotes: 1

Views: 2382

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123996

There are some problems with this build script:

  • eclipse doesn't refer to the task but to the equally named model object. (Don't you get an exception for eclipse.dependsOn?)
  • Task copyJars does its work in the configuration phase rather than the execution phase (i.e for every build, even if the task isn't executed)

To fix that, use tasks.eclipse.dependsOn(copyJars) and task copyJars << { ... }.

Another question is if there isn't a simpler way than copying things around with copyJars and fixing up the Eclipse class path after the fact, but I'd need more information to be able to tell.

Upvotes: 3

Related Questions