1

I'm developing a Maven 3 plugin by using Groovy together with Maven Annotation Support. In a Mojo class, it seems that name or alias of @Parameter aren't reflected during the runtime:

@Parameter(required = true, name = "pathAsAName", alias = "pathAsAnAlias")
File pathAsAField

The only way to set the field from the Maven XML configuration is by using

<configuration>
      <pathAsAField>/tmp</pathAsAField>
</configuration>

and not by using <pathAsAName> (or <pathAsAnAlias> which I'm not sure what it is exactly for) regardless of the fact that plugin.xml contains

<parameter>
      <name>pathAsAName</name>
      <alias>pathAsAnAlias</alias>
      <type>java.io.File</type>
      <required>true</required>
      <editable>true</editable>
      <description></description>
</parameter>

When I use <pathAsAName>/tmp</pathAsAName> I get an error:

[ERROR] Failed to execute goal ... on project ...: Unable to parse configuration of mojo ...:...:...:... for parameter pathAsAName: Cannot find 'pathAsAName' in class ... -> [Help 1]

I'm using maven-core:3.3.3 and maven-plugin-annotations:3.4. And execute it with Maven 3.3.3.

Stepan Vavra
  • 3,884
  • 5
  • 29
  • 40
  • By definition, ``Parameter`` is annotated with ``@Retention(RetentionPolicy.CLASS)`` (the default, [sadly](http://stackoverflow.com/questions/5971234/retentionpolicy-class-vs-runtime)) – Binkan Salaryman Jun 18 '15 at 11:11
  • I see. Does it mean the author (Olivier Lamy in this case) intended to use a class post-processor that would generate "something" "somewhere" (such as `maven-plugin-plugin` with its goal `descriptor`) so that this information can be used for the configuration purposes? But sadly, it is not used at all, if I understand it right? – Stepan Vavra Jun 18 '15 at 11:19
  • ``RetentionPolicy.CLASS`` instructs the compiler to record reflection metadata in the corresponding *.``class`` file, but it cannot be received with the reflection API at runtime. I think it would be interesting to hack on that... :D – Binkan Salaryman Jun 18 '15 at 11:25
  • You mean to record annotation metadata, right? – Stepan Vavra Jun 18 '15 at 11:28
  • Well, some of the annotation metadata is used anyway such as "property" and others which makes it even more confusing for me. – Stepan Vavra Jun 18 '15 at 11:30
  • Experimentally, it should be possible to read left information. But I don't recommend to use such code in a productive environment. The class ``Class`` retrieves the annotation metadata with ``native byte[] getRawAnnotations();`` – Binkan Salaryman Jun 18 '15 at 11:31

0 Answers0