maven

框架

apache/maven

Java 项目构建管理与项目理解工具。

项目简介

Maven 是基于项目对象模型(POM)的软件项目管理工具,集中管理构建、报告和文档,支持可重现构建和依赖管理。

README 预览

\nApache Maven\n============\n\n[][license]\n[](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/maven/README.md)\n\n- [master](https://github.com/apache/maven) = 4.1.x\n[][build]\n[][gh-build]\n\n- [4.0.x](https://github.com/apache/maven/tree/maven-4.0.x): \n[](https://central.sonatype.com/artifact/org.apache.maven/apache-maven)\n[][build-4.0]\n[][gh-build-4.0]\n\n- [3.10.x](https://github.com/apache/maven/tree/maven-3.10.x):\n[][build-3.10]\n[][gh-build-3.10]\n\n- [3.9.x](https://github.com/apache/maven/tree/maven-3.9.x): \n[](https://central.sonatype.com/artifact/org.apache.maven/apache-maven)\n[][build-3.9]\n[][gh-build-3.9]\n\nApache Maven is a software project management and comprehension tool. Based on\nthe concept of a project object model (POM), Maven can manage a project's\nbuild, reporting and documentation from a central piece of information.\n\nIf you think you have found a bug, please file an issue in the [Maven Issue Tracker](https://github.com/apache/maven/issues).\n\nDocumentation\n-------------\n\nMore information can be found on [Apache Maven Homepage][maven-home].\nQuestions related to the usage of Maven should be posted on\nthe [Maven User List][users-list].\n\n\nWhere can I get the latest release?\n-----------------------------------\nYou can download the release source from our [download page][maven-download].\n\nContributing\n------------\n\nIf you are interested in the development of Maven, please consult the\ndocumentation first and afterward you are welcome to join the developers\nmailing list to ask questions or discuss new ideas/features/bugs etc.\n\nTake a look into the [contribution guidelines](CONTRIBUTING.md).\n\nLicense\n-------\nThis code is under the [Apache License, Version 2.0, January 2004][license].\n\nSee the [`NOTICE`](./NOTICE) file for required notices and attributions.\n\nDonations\n---------\nDo you like Apache Maven? Then [donate back to the ASF](https://www.apache.org/founda

常见问题 (5)

故障排除
如何修复嵌入式 Maven 3.10.0 忽略 --color=yes 并且在使用 MavenCli.doMain 时不产生 ANSI 输出的问题?

这是 Maven 3.10.0 中的一个回归问题。在 JAnsi 到 JLine 的迁移之后,MessageUtils.isColorEnabled() 要求 colorEnabled 标志和非 null 的 Terminal 同时满足。MavenCli.main(...) 会安装终端,但通过 MavenCli.doMain(...) 进行的嵌入式调用不会安装,因此 --color=yes 虽然设置了标志位,ANSI 输出却仍然处于禁用状态。

修复方法:使用包含 PR #13358 的 Maven 3.10.x 构建版本,或相应的已修复发布版本。该修复使 doMain 在嵌入式调用时通过 MessageUtils.systemInstall(Terminal) 安装一个 dumb-color JLine 终端,并在调用结束后将其移除;无需引入新的 API。

临时变通方法:
1. 将嵌入式 Maven 运行时降级到 3.9.x,例如 maven-embedder 3.9.16,在该版本中 --color=yes 可以正常生效。
2. 以 fork 方式运行 Maven,而不是使用嵌入式执行器(EmbeddedMavenExecutor);fork 执行器在 3.10.0 上可以正常工作。
3. 如果在维护自定义的嵌入器,请在调用 doMain 之前使用 MessageUtils.systemInstall(...) 安装一个支持颜色的 JLine Terminal,并在 finally 块中恢复/移除它。建议优先升级到已修复的 Maven 版本,因为这种方式使用了 Maven 内部 API。

使用 mvn -v 验证运行时版本,然后带上 --color=yes 重新运行嵌入式命令。

来源 Issue #13357
故障排除
如何修复 Maven 3.10.0 中内部工件出现的 'ArtifactFilteredOutException: prefixes: Path NOT allowed from central' 错误?

Maven 3.10.0 使用 Resolver 2.0.x,其中远程仓库前缀过滤默认启用。如果 Artifactory/Nexus 提供的 prefixes.txt 仅基于公共 Maven Central 索引生成,那么聚合虚拟仓库中的内部构件即使存在且可直接下载,也会被阻止获取。

临时解决办法:为构建禁用前缀过滤:

mvn -Daether.remoteRepositoryFilter.prefixes.enabled=false clean verify

若要持久应用,请将以下行添加到 .mvn/maven.config:

-Daether.remoteRepositoryFilter.prefixes.enabled=false

如有必要,可以使用以下命令禁用所有远程仓库过滤器:

mvn -Daether.remoteRepositoryFilter.enabled=false clean verify

这只是临时解决办法。永久修复方案是让仓库管理器提供包含内部构件路径的正确 prefixes.txt,或者停止为聚合仓库提供不正确的前缀文件。降级到 Maven 3.9.x 也可以避免此问题,因为它使用 Resolver 1.x,默认不会拉取前缀文件。

来源 Issue #13385
故障排除
如何修复 Maven 4 中第二次执行插件时 MojoExecution.getPlugin().getDependencies() 抛出的 NullPointerException?

此问题出现在 Maven 4.0.0-rc-7 中,当插件的类 realm 由 PluginRealmCache 提供时。缓存会恢复类 realm 和构件,但不会恢复解析器的依赖节点,因此在后续执行中 PluginDescriptor.getDependencyNode() 为 null。请升级到包含该修复的 Maven 4 构建版本,在该版本中 PluginRealmCache.CacheRecord 会保留依赖节点,并由 DefaultMavenPluginManager.setupPluginRealm() 将其恢复。如果是从源码构建 Maven,请应用上游修复:将 DependencyNode 存储到缓存记录中,并在恢复缓存的 realm 时一并恢复它。作为临时解决方案,可以避免在一次构建中多次绑定同一个插件,或者合并这些插件执行。

来源 Issue #13307
故障排除
为什么 `mvnup check` 在试运行(dry run)期间会报告 "POM(s) modified" 和 "Plugin upgrades applied"?

这是 Apache Maven 4.0.0-rc-7 中的一个误导性输出 bug。mvnup check 执行的是 dry run,并不会写入 POM 文件,尽管其报告声称升级已应用且 POM 已被修改。可以使用 cp pom.xml /tmp/before.xml && mvnup check && diff /tmp/before.xml pom.xml 进行验证;此时不应报告任何差异。该修复会跟踪 dry-run 状态,并将措辞更改为计划性操作的文本,例如 "would upgrade" 和 "POM(s) would be modified"。请升级到包含 PR "fix: clarify mvnup check dry-run output" 的 Maven 版本(或使用该 PR 从源码构建 Maven)。在此之前,请将 check 的输出仅视为预览;仅当确实希望写入更改时,才运行相应的 apply/write goal。

来源 Issue #13250
故障排除
如何修复在 Maven 4 扩展中通过 PackagingProvider 贡献 packaging 时出现的 "Unknown packaging" 错误?

这是 Maven 4.0.0-rc-7 以及当前 master 分支中的一个 bug:DefaultPackagingRegistry.lookup() 只检查旧版的 Sisu LifecycleMapping,而忽略了注入的 List<PackagingProvider>,因此诸如 app-client 之类贡献的 packaging 会失败,并报错 Unknown packaging: app-client。

修复方法:
1. 将 Maven 升级到包含 PR #13319 的版本;如果尚未有可用版本,则从该分支构建 Maven。
2. 该补丁使 DefaultPackagingRegistry 读取注入的 PackagingProvider 实例,并在回退到 LifecycleMapping 之前按 ID 解析它们的 packaging。

在修复发布前的临时解决方案:保留 META-INF/plexus/components.xml 中的 Maven 3/Plexus 注册,并将自定义 packaging ID 注册为 LifecycleMapping 组件。不要仅依赖 PackagingProvider/TypeProvider。恢复该描述符后重新构建扩展。这会影响 maven-acr-plugin、maven-rar-plugin、maven-jmod-plugin 和 maven-jlink-plugin 所使用的 packaging。

来源 Issue #13306