2
$ ant clean compile notexist install

Here I get BUILD FAILED because notexist doesn't exist as a target, which is expected. But is there anyway to just ignore or skip unknown targets? Or maybe map unknown targets to a known target (which would be a no-op for me)?

Background

We are using Atlassian Bamboo for our CI server, and whenever we want to add an ant target to our build, we run the risk of breaking older branches of code. This is because if we run an old build through our CI, it may not contain the target and therefore fail. Thus we are reduced to editing the build.xml file, and either use depends or <ant>, but this doesn't give us the flexibility we desire.

Example

Today we have:

ant clean selenium.tests

We want to add a new target to test our REST services. Target is rest.tests. Thus, I want my command to be

ant clean selenium.tests rest.tests

But for old branches, rest.tests doesn't exist yet. Our solution up to now has been to add rest.tests as a dependency of selenium-tests (since our build.xml is under version control), but this means we can't run selenium.tests by itself.

In hindsight, we should have just created a proxy target, such as integration.tests (we already use test for unit tests) which would delegate to both of these two targets. But unless there is a solution to my original question, we can't even add integration.tests to the CI.

Sean Adkinson
  • 8,425
  • 3
  • 45
  • 64
  • your ant file isn't in source control with the rest of your project? – thekbb Oct 08 '13 at 00:39
  • The ant file is git, but in Bamboo or Jenkins or any CI, you tell it what targets to execute, and that isn't in version control. So if we try to run a successful build from an older branch (maybe to release a bugfix) we run our plan, which now might have newer ant targets. Make sense? – Sean Adkinson Oct 08 '13 at 04:14
  • can't you just call clean and install and have the dependencies in the ant file work it all out? – thekbb Oct 08 '13 at 18:25
  • Updated the question with our actual targets and my current issue. – Sean Adkinson Oct 08 '13 at 23:01

2 Answers2

0

You may have to invoke ant programmatically. Discussed here in Running ANT Programmatically Through Java

The org.apache.tools.ant.Project provides list of targets and way to invoke it

Community
  • 1
  • 1
Jayan
  • 18,003
  • 15
  • 89
  • 143
0

I don't think there is a way to test that a target (rather than a file) exists as you call it. My suggestions are:

  1. How often do you build old versions which have missing targets? If it sufficiently infrequent that you can take the pain of manually commenting out those calls in the CI config?
  2. Can you limit your CI calls to a tidy set which will generally be there: clean, build, test, dist etc?
  3. Do you need to split the CI config into multiple jobs? If you really need targets which aren't there in some versions maybe you have radically different versions of your product that merit separation into different CI jobs. Then it won't make sense to build the job for which the target doesn't exist.
Dan
  • 358
  • 1
  • 11