FYI: I opened GROOVY-7522 and GROOVY-7523 which, if agreed to, will make your config script a lot simpler.


On Fri, Jul 17, 2015 at 4:49 PM, Keegan Witt <> wrote:
Awesome!  Glad I could help.

On Fri, Jul 17, 2015 at 12:48 PM, Nikolay Totomanov <> wrote:
Thanks a lot, Keegan!
It works like a charm!

>-------- Оригинално писмо --------
>От: Nikolay Totomanov
>Относно: Re: Always add no-args constructor at compile time
>Изпратено на: 15.07.2015 01:57

The code looks very clean to me!
Thanks a lot, Keegan!
I'll give it a try.

>-------- Оригинално писмо --------
>От: Keegan Witt
>Относно: Re: Always add no-args constructor at compile time
>Изпратено на: 14.07.2015 06:04

Oh, actually Opcodes is not needed, you can take that off so you don't need a dependency on org.ow2.asm:asm.

On Mon, Jul 13, 2015 at 10:53 PM, Keegan Witt <> wrote:
Here's what I'm thinking.  Use this as a configuration script.
import java.lang.annotation.ElementType
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import java.lang.annotation.Target
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.ast.AnnotatedNode
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.ConstructorNode
import org.codehaus.groovy.ast.Parameter
import org.codehaus.groovy.ast.stmt.BlockStatement
import org.codehaus.groovy.control.CompilePhase
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.transform.AbstractASTTransformation
import org.codehaus.groovy.transform.GroovyASTTransformation
import org.codehaus.groovy.transform.GroovyASTTransformationClass
import org.objectweb.asm.Opcodes

@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
public class DefaultConstructorASTTransformation extends AbstractASTTransformation implements Opcodes {
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source)
AnnotatedNode parent = (AnnotatedNode) nodes[1]

if (parent instanceof ClassNode) {
ClassNode cNode = (ClassNode) parent
if (!cNode.getDeclaredConstructor(new Parameter[0])) {
final BlockStatement body = new BlockStatement()
cNode.addConstructor(new ConstructorNode(ACC_PUBLIC, new Parameter[0], cNode.EMPTY_ARRAY, body))
public @interface DefaultConstructor {}

withConfig(configuration) {

Seemed to work in my tests, but everybody should feel free to point out anything I goofed up.


On Mon, Jul 13, 2015 at 6:24 PM, Keegan Witt <> wrote:
Sorry, I should have given you the example in the configuration script syntax

withConfig(configuration) {
ast(groovy.transform.TupleConstructor, includes:[''])

But it doesn't matter, because the transformation removes existing constructors from the class.  Sorry, I got ahead of myself.


On Mon, Jul 13, 2015 at 5:45 PM, Keegan Witt <> wrote:
One way that comes to mind offhand would be
    @groovy.transform.TupleConstructor(includeFields=false, includeProperties=false, includeSuperFields=false, includeSuperProperties=false)


Anybody know why
doesn't work?


On Mon, Jul 13, 2015 at 5:34 PM, Nikolay Totomanov <> wrote:

I need to always add the default constructor to my classes.
Is it possible to achieve that using CompilerConfiguration