是否可以在 Maven 插件的配置块中使用 XML 属性?

发布于 2024-12-25 11:10:09 字数 453 浏览 3 评论 0原文

我想开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫林﹌晚霞¤ 2025-01-01 11:10:09

我知道我这个问题迟到了,但我认为答案是不同的。毕竟, 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 an ant 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 basic getChildren/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."

终止放荡 2025-01-01 11:10:09

没有。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文