Setting compiler args in new language plugin


(Tudor Timi) #1

I’m developing a plugin for a new language and I was trying to add support for compile options to the compiler. I’ve used the org.gradle.api.tasks.compile.CompileOptions class as a starting point and implemented my own class as following:

class SvCompileOptions extends AbstractOptions {
    private List<String> compilerArgs = Lists.newArrayList();

    @Input
    public List<String> getCompilerArgs() {
        return compilerArgs;
    }

    public void setCompilerArgs(List<String> compilerArgs) {
        this.compilerArgs = compilerArgs;
    }
}

In my build.gradle file, I’ve tried doing the following:

compileSv {
    options.compilerArgs += [ "-foo" ]
}

(compileSv is a task with an options property of type SvCompileOptions.)

I get the following error:

A problem occurred evaluating project ':uvc2'.
> java.lang.AbstractMethodError (no error message)

If I replace the line with:

compileSv {
    options.compilerArgs.add("-foo")
}

then everything works fine, but it’s not very gradlesque.

Can someone please point out what I’m doing wrong?