java - 将 maven pom.xml 上传到 Git 存储库?

标签 java git maven github pom.xml

我想在 GitHub 上发布我的 Java 项目。我不确定是否应该从我的存储库中的 Maven 上传我的 pom.xml

我使用的是没有 eGit 的 Eclipse。

一方面:

  • pom.xml 是了解我使用了哪些库所必需的。

另一方面:

  • 这是一个可能不应该公开的配置文件。
  • 它破坏了一个干净的 repo 的外观,因为它在正常的源文件之外。

我应该怎么做最好?

最佳答案

  • it's a configuration file which maybe shouldn't made public.

这是错误的。 POM 确实是一个配置文件,但它的目的是让这个文件公开。实际上,引用 Maven guide to uploading artifacts to the Central Repository :

Some folks have asked why do we require all this information in the POM for deployed artifacts so here's a small explanation. The POM being deployed with the artifact is part of the process to make transitive dependencies a reality in Maven. The logic for getting transitive dependencies working is really not that hard, the problem is getting the data. The other applications that are made possible by having all the POMs available for artifacts are vast, so by placing them into the repository as part of the process we open up the doors to new ideas that involve unified access to project POMs.

如您所见,实际上需要此文件,以便可以将 Artifact 上传到 Maven Central。

不应该公开的是您的设置,即 settings.xml 文件。您应该在此文件中存储任何敏感信息,例如密码。再次引用 Settings Reference (强调我的):

The settings element in the settings.xml file contains elements used to define values which configure Maven execution in various ways, like the pom.xml, but should not be bundled to any specific project, or distributed to an audience. These include values such as the local repository location, alternate remote repository servers, and authentication information.

如果您目前在 POM 中存储任何敏感信息,您应该考虑重构它以提取此信息并将其放入您的设置中。


  • it destroys the look of a clean repo, because it's outside of the normal source files.

一个源文件,Maven 唯一的要求就是这个文件的存在。它描述了如何构建您的应用程序并声明其所有依赖项。换句话说:这个文件是一个 Maven 源文件,因此应该与项目主要源文件一起提交。没有它,没有人可以构建您的应用程序,也没有人可以打包它。

关于java - 将 maven pom.xml 上传到 Git 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33574970/

相关文章:

git - 用于检查指定的 Git 分支是否存在的 Shell 脚本?

java - 无法为 Storm-starter 示例构建 Storm

java - Java 和 Ruby 之间的正则表达式差异

java - 如何在 Android 上触摸通知时导航到特定的 React 组件?

用于网站暂存的 Git 接收后 Hook

java - spring-boot react 堆 java.lang.ClassNotFoundException MultiReaderFastList

maven - 在 Jenkins 上构建 Maven 后将 webapp 部署到 Tomcat

java - 使用 Java 中的 Scanner 类读取 .txt 文件

java - 如何依赖两个不同版本的库?

计算机死机后 Git 存储库损坏