Is it possible to make a parameter configurable ONLY via its alias?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Is it possible to make a parameter configurable ONLY via its alias?

Tad Cordle
I'm working on a plugin
<> that
has nested parameters, and I'd like to introduce aliases to give people the
option of more concise configuration. For example, instead of writing:


they can instead write:


However, it doesn't seem to be possible to declare aliases directly on
nested parameters. My workaround for this is to create a new top-level
field for each parameter. For example, the original configuration is
possible using this in the mojo:

public static class AuthConfiguration {
  @Parameter private String username;
  @Parameter private String password;
public static class FromConfiguration {
  @Parameter private String image;
  @Parameter private AuthConfiguration auth = new AuthConfiguration();
@Parameter private FromConfiguration from = new FromConfiguration();

And to create an alias, I add a new field, and choose one of the values in
the getter:

@Parameter(alias = "from.image")
private String fromImageAlias;

String getFromImage() {
  if (fromImageAlias != null) {
    return fromImageAlias;
  return from.image;

This works, but since the alias is just an alias and not a replacement for
the field name, it's still possible to configure the parameter using the
name of the field. e.g.


Is it somehow possible to expose a parameter only by its alias, and
disallow configuration using the field name? Or even better, is there a way
of configuring aliases on nested parameters that I don't know about?

P.S. I notice the maven docs
 say "nested bean injection requires Sisu or JSR330 annotations". Can this
be used to accomplish what I'm looking for, and if so how?