The reason it works in ant is because the groovy runtime is explicitly added to the groovyc invocation, which is passed onto the javac process. The command line in this bug passes in no classpath.
As to why it works when the java classes have no dependency on the groovy classes has to do with how javac works. Only the native java classes needing compilation are passed into the javac call, so whether or not foo is empty only Foo.java is passed in as an argument, not the Bar.groovy stub. When compiling an empty or non-dependent foo javac never needs to look at any of the stubs, so it doesn't try. But when we reference a stub class javac then trys to resolve the class or compile the stub. Since the stubed Bar.java is in the sourcepath passed into javac in the expected palace, javac then tries to compile it. Javac, however, only looks to the command line classpath to get classes. Even though groovy is in the system classpath javac won't look there (unlike groovyc). Hence the jar containing the groovy classes needs to be passed in the javac -classpath argument.
We could require the user to do this, but this seems surprising to the user. This is also difficult because the name of the groovy jar always changes between versions (unlike java's rt.jar), and the location may be quite inconvenient, depending on where you installed groovy. Even worse, it may need to be the same version jar that groovyc is compiling against to insure API compatibility, since we don't support cross-version compilation..