Index: java/org/apache/ivy/ant/BuildNumberIvy1037.java
===================================================================
--- java/org/apache/ivy/ant/BuildNumberIvy1037.java	(revision 0)
+++ java/org/apache/ivy/ant/BuildNumberIvy1037.java	(revision 0)
@@ -0,0 +1,87 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.ant;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Delete;
+
+public class BuildNumberIvy1037 extends TestCase {
+    private File cache;
+
+    private IvyBuildNumber buildNumber;
+
+    protected void setUp() throws Exception {
+        createCache();
+        Project project = new Project();
+        project.setProperty("ivy.settings.file", "test/repositories/IVY-1037/ivysettings.xml");
+
+        buildNumber = new IvyBuildNumber();
+        buildNumber.setProject(project);
+    }
+
+    private void createCache() {
+        cache = new File("build/cache");
+        cache.mkdirs();
+    }
+
+    protected void tearDown() throws Exception {
+        cleanCache();
+    }
+
+    private void cleanCache() {
+        Delete del = new Delete();
+        del.setProject(new Project());
+        del.setDir(cache);
+        del.execute();
+    }
+
+    public void testResolve1() throws Exception {
+        buildNumber.setOrganisation("org");
+        buildNumber.setModule("module");
+        buildNumber.setResolver("rep1");
+        buildNumber.execute();
+        assertEquals("2", buildNumber.getProject().getProperty("ivy.new.revision"));
+    }
+
+    public void testResolve2() throws Exception {
+        buildNumber.setOrganisation("org");
+        buildNumber.setModule("module");
+        buildNumber.setResolver("rep2");
+        buildNumber.execute();
+        assertEquals("3", buildNumber.getProject().getProperty("ivy.new.revision"));
+    }
+
+    /**
+     * Here is the Bug 1037. The Buildnumbe Task should take in account both child resolvers of the
+     * cain resolver and thus return 3.
+     * 
+     * @throws Exception
+     */
+    public void testResolveChain() throws Exception {
+        buildNumber.setOrganisation("org");
+        buildNumber.setModule("module");
+        buildNumber.setResolver("chain");
+        buildNumber.execute();
+        assertEquals("3", buildNumber.getProject().getProperty("ivy.new.revision"));
+    }
+
+}
Index: repositories/IVY-1037/ivysettings.xml
===================================================================
--- repositories/IVY-1037/ivysettings.xml	(revision 0)
+++ repositories/IVY-1037/ivysettings.xml	(revision 0)
@@ -0,0 +1,15 @@
+<ivyconf>
+    <conf defaultResolver="chain"/>
+    <resolvers>
+        <chain name="chain" >
+            <filesystem name="rep1" >
+                <ivy pattern="${ivy.settings.dir}/rep1/[organisation]/[module]/ivy-[revision].xml"/>
+                <artifact pattern="${ivy.settings.dir}/rep1/[organisation]/[module]/[artifact]-[revision].[ext]"/>
+            </filesystem>
+            <filesystem name="rep2" >
+                <ivy pattern="${ivy.settings.dir}/rep2/[organisation]/[module]/ivy-[revision].xml"/>
+                <artifact pattern="${ivy.settings.dir}/rep2/[organisation]/[module]/[artifact]-[revision].[ext]"/>
+            </filesystem>
+        </chain>
+    </resolvers>
+</ivyconf>
\ No newline at end of file
Index: repositories/IVY-1037/rep1/org/module/ivy-1.xml
===================================================================
--- repositories/IVY-1037/rep1/org/module/ivy-1.xml	(revision 0)
+++ repositories/IVY-1037/rep1/org/module/ivy-1.xml	(revision 0)
@@ -0,0 +1,22 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.    
+-->
+<ivy-module version="2.0">
+    <info organisation="org" module="module" revision="1" status="integration" publication="20090108103716"/>
+    <publications/>
+</ivy-module>
Index: repositories/IVY-1037/rep2/org/module/ivy-2.xml
===================================================================
--- repositories/IVY-1037/rep2/org/module/ivy-2.xml	(revision 0)
+++ repositories/IVY-1037/rep2/org/module/ivy-2.xml	(revision 0)
@@ -0,0 +1,22 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.    
+-->
+<ivy-module version="2.0">
+    <info organisation="org" module="module" revision="2" status="integration" publication="20090108103716"/>
+    <publications/>
+</ivy-module>
