Hi folks,

I have been holding back the next round of releases for a couple of weeks
now hoping we could assist the Grails team with their reproducible build
goals. PR#2229 seems to address the problem:

https://github.com/apache/groovy/pull/2229

My plan is to merge into 4_0_X (and master) and then kick off the next
releases. Please let me know if you have any concerns.

Some further background. We aren't quite sure what triggers the problem,
but it isn't specific to Grails. If you look at the Javadoc for
java.lang.Class#getMethods, it states that "The elements in the returned
array are not sorted and are not in any particular order.". We use the
order when injecting trait methods and historically it was often the order
of appearance in the source code but was never guaranteed. Now we are
seeing different orders for subsequent build invocations and no other
changes. What this means is that for two separate compilation runs, the
generated class files can be different with no change in input. This makes
it harder to produce reproducible builds and hinders the ability of build
tools to perform optimum caching.

PR#2229 embeds the line number (within an annotation) of trait members into
the generated interface and helper classes. When injecting, we preserve the
order using that information. Class files are very slightly bigger and
there is a small performance penalty sorting during compilation, but in
return, the builds become reproducible. If the line number annotations
aren't found, ordering is no worse off than what we have now. If we can
find a better solution, it is relatively easy to back out this change
without huge compatibility implications.

Let me know if you have any thoughts.

Cheers, Paul.

Reply via email to