0

I've got a Ant build script which I need to compile part of my project (it links into a third-party build system for the JavaScript libraries we use).

I want to wrap Gradle around this, so I've imported the Ant build, and I can successfully invoke the Ant targets via Gradle. I've even added input and output checking to the targets, so that they won't run if they don't need to

The Ant targets have setup work that they do - mostly importing configurations and settings. They do this via a dependency on an init target, which takes about 4-5 seconds to run. What I would like to do is prevent that init target running if the inputs on the main task have been satisfied.

Any suggestions?

Example Ant build script (build.xml):

<?xml version="1.0" encoding="utf-8"?>
<project name="MyProject" default="build">
  <target name="init" />
  <target name="build" depends="init">
    <echo message="hello" file="output.txt" />
  </target>
</project>

Example Gradle script to go with it (build.gradle):

ant.importBuild 'build.xml'

build {
  inputs.dir file('src')
  outputs.file file('output.txt')
}

Ideally, when I run gradle build, I don't want init to run if build is up-to-date.

Any suggestions?

Robert Watkins
  • 2,196
  • 15
  • 17
  • One obvious answer, BTW, would be to simply define new tasks that delegate down to the old ones - but I would like to keep the task names that the existing `build.xml` uses. If I can do namespacing on the imported tasks or similar, that would be an acceptable answer – Robert Watkins Jul 25 '14 at 06:45
  • Well, it does a bunch of stuff. Mostly it sucks in configuration variables used in the actual targets; they won't work without it having been run, so they naturally include it as a dependency. It doesn't produce any output of its own, though. The above example is simplified for brevity. – Robert Watkins Jul 25 '14 at 20:57

1 Answers1

0

The up-to-date check for build will only happen after init has run. What you can do is to declare the same inputs for init, and if it has no file outputs, outputs.upToDateWhen { true }. Perhaps this meets your needs.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • That's kind of what I thought. Putting the checks on init, though, isn't possible - there are a number of such targets that have the dependency on init, and they have different outputs and inputs. What I'll probably end up doing is adding extra targets that invoke the main targets inside them _after_ doing the up-to-date checks. – Robert Watkins Jul 26 '14 at 06:07