我已经阅读了有关 Maven 并行构建配置的信息。那么如何显示所有非线程安全的插件呢?maven 中有类似“plugin-not-safe-list”命令的东西吗?
REM something like that to display all p[lugins without @threadSafe annotation
mvn help:plugin-not-safe-list
我已经阅读了有关 Maven 并行构建配置的信息。那么如何显示所有非线程安全的插件呢?maven 中有类似“plugin-not-safe-list”命令的东西吗?
REM something like that to display all p[lugins without @threadSafe annotation
mvn help:plugin-not-safe-list
现在,当您构建 Maven 时会警告未标记为线程安全的插件:
[WARNING] *****************************************************************
[WARNING] * Your build is requesting parallel execution, but project *
[WARNING] * contains the following plugin(s) that have goals not marked *
[WARNING] * as @threadSafe to support parallel building. *
[WARNING] * While this /may/ work fine, please look for plugin updates *
[WARNING] * and/or request plugins be made thread-safe. *
[WARNING] * If reporting an issue, report it against the plugin in *
[WARNING] * question, not against maven-core *
[WARNING] *****************************************************************
[WARNING] The following plugins are not marked @threadSafe in Root Maven Parent:
[WARNING] com.googlecode.maven-download-plugin:download-maven-plugin:1.3.0
[WARNING] Enable debug to see more precisely which goals are not marked @threadSafe.
[WARNING] *****************************************************************
您可以为maven-enforcer-plugin编写自定义规则并将其用于在您的 maven 项目上运行。
您可能还想使用mojo-executor来解析plugin.xml
文件以检查其“线程安全”属性。
详细说明何时以及为什么应该使用上述内容。当你在 CI/CD 环境中工作,并且你想通过 maven 使用并行编译时,你应该经常监控你的开发人员没有添加非线程安全的插件,以确保 CI/CD 的一致性和正确性. 为了实现这一点,您可以使用上面提到的maven-envorcer-plugin和自定义规则。您的自定义规则可以使用 Maven 插件 API(maven 项目等)来搜索项目中的所有插件,然后使用mojo-executor库来读取threadSafe
每个插件的属性(因为 maven API 确实不提供)。mojo-executor lib 具有解析plugin.xml
maven 插件文件的工具,其中threadSafe
财产居住。一旦找到,您可以使 Maven 构建失败。
如果您只想查看非线程安全插件的列表,您可以使用相同的技术,只列出threadSafe
属性为 false 的插件。然后,您可以将其配置maven-enforcer-plugin
为使用自定义规则(例如,项目的配置文件),并通过命令行在单个 maven 命令中运行它。
顺便说一句,当您在开发项目中发现非线程安全插件并且没有线程安全替代方案时会发生什么,这是另一个问题,这也是可以解决的。