是否可以在 Maven 插件的配置块中使用 XML 属性?
我想开发一个 Maven 插件,作为其配置的一部分(将映射到 mojo 字段),我想在一些标签上提供 XML 属性。不幸的是,官方指南没有提到使用配置块中的属性(这可能意味着也可能不意味着它根本不可能。)
我想要的是:
<plugin>
<configuration>
<my_option attr="x" /> <!-- is this possible? -->
</configuration>
</plugin>
这可能吗?如果是这样,这将如何映射到我的魔力中的字段?
I want to work on a Maven plugin, and as part of its configuration (which will be mapped to the mojo fields), I'd like to supply XML attributes on a few tags. Unfortunately, the official guide makes no mention of the use of attributes in configuration blocks (which may or may not mean that it's simply not possible.)
What I'd like to have is this:
<plugin>
<configuration>
<my_option attr="x" /> <!-- is this possible? -->
</configuration>
</plugin>
Is this possible at all? If so, how will this map to a field in my mojo?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道我这个问题迟到了,但我认为答案是不同的。毕竟, Maven antrun 插件 的工作方式与OP完全相同通缉;查看
target
如何提供可在ant
构建文件中使用的任何 XML。这是通过在 mojo 中声明 PlexusConfiguration 类型的参数来完成的,
请参阅 第 164-171 行左右。
PlexusConfiguration
没有扩展任何众所周知的 XML API,例如 DOM,并且似乎不支持命名空间、PI 等,但它具有基本的getChildren
/< code>getAttributeNames/getAttribute
方法,您希望用于大多数目的。是否还有办法在 较新的 JSR-330(非 Plexus) 中执行此操作我不知道,但就 Plexus API 而言,文档确实说“这些 API 将永远受到支持,或者至少在 Maven 完全放弃 Maven 2 支持之前”。
I know I'm late to the question, but I think the answer is different. After all, the Maven antrun plugin works exactly the way the OP wanted; look at the way
target
can supply any XML you could use in anant
build file.It's done in the mojo by declaring that parameter with type
PlexusConfiguration
,see around lines 164-171.
PlexusConfiguration
doesn't extend any well-known XML API such as DOM, and it seems not to support namespaces, PIs, etc., but it has the basicgetChildren
/getAttributeNames
/getAttribute
methods you would want for most purposes.Whether there's also a way to do it in the newer JSR-330 (non-Plexus) way, I don't know, but as far as the Plexus APIs go, the doc does say "those APIs will be supported forever, or at least until Maven fully drops Maven 2 support."
没有。 Maven 不支持属性。但是,您可以使用字符串映射等。例如,看看编译器插件如何在 dex mojo 配置中执行 compilerArguments 或 Android Maven 插件(您正在使用的)如何执行 jvmArguments 。
Nope. Maven does not support attributes. You can however use a map of strings or so. Look at e.g how the compiler plugin does compilerArguments or how the Android Maven Plugin (on which you are working) does jvmArguments in the dex mojo configuration.