So, I'm struggling to <add command line options to...
# plugin-development
j
So, I'm struggling to add command line options to a plugin's custom task. For specifics, I'm playing with the JMH plugin for Gradle. I'd like to be able to run the task with different JVM parameters without modifying the build.gradle file. The JMHTask defines most of its inputs in an interface. Try as I might, I can't find a good way to add command line options to that task without dramatically rewriting the plugin (and not just the task). From what I can see of the examples (and what I've gleaned from trying different things with the code), you can't add the
@Option
annotation to an abstract method (like those defined on an interface) unless it takes a boolean. See, for example, the UrlProcess example under the "Documenting available values..." heading. While there's an
Option
annotation on the abstract
getHttp
method, the URL string has a concrete setter & getter method. If I try just adding the
@Option
annotation to new setter methods on the interface, the plugin fails to apply. See (00536a1ade7dd) If I try adding default implementations to the setters, even in a separate interface, just for the setters (see 074302bc9ce0), I get errors like:
Could not generate a decorated class for type JMHTask. > Cannot have abstract method JmhParameters.getIncludes().
. In other words, adding concrete setters of any kind breaks the abstract getters. Yet the getters being abstract is relied on for other parts of the plugin!) If I just add concrete setter methods to the task class (which is abstract), and throw the
@Option
annotations on those, and make the getter methods concrete, the plugin itself fails because it's built to rely on generating properties from the abstract class (see b7b1a38312). Anyone got any tips on adding command line options to Gradle tasks in a way that still lets you have abstract getters? Documentation says there's no programmatic way to do it, so I figure I'm stuck with making the annotation work.