I looked into it a bit and I know what is causing it but I have no idea how to fix it.
The reason re-ordering of the classes in the source file is not having any effect is that ACG sorts the classes that it generates (needSortedInput() for classgen returns true) and the sorting is by the length of the hierarchy of the class (its distance from java.lang.Object).
So, when MainInvokeSub does not extend MainInvokeBase, length of type hierarchy of MainInvokeSub and SecondClass is same and you get back MainInvokeSub as the class to run from the source file, if it is present first in the source file.
But when MainInvokeSub extends MainInvokeBase, its type hierarchy is longer than SecondClass's and after sorting in ACG SecondClass comes ahead in order and becomes the class to run (by being the first class to be pushed from ACG to GroovyClassLoader$ClassCollector), and running it fails because it does not have any main method, etc.
Any suggestion on what I can explore to fix it?