简体   繁体   English

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

[英]Upload maven pom.xml to Git repository?

I want to publish my Java project on GitHub. 我想在GitHub上发布我的Java项目。 I'm not sure if I should upload my pom.xml from Maven in my repository. 我不确定是否应该从我的存储库中的Maven上传我的pom.xml

I'm using Eclipse without eGit. 我在没有eGit的情况下使用Eclipse。

On the one hand: 一方面:

  • the pom.xml is necessary to know which libraries I used. pom.xml是知道我使用哪些库的必要条件。

On the other hand: 另一方面:

  • it's a configuration file which maybe shouldn't made public. 它是一个配置文件,可能不应该公开。
  • it destroys the look of a clean repo, because it's outside of the normal source files. 它破坏了一个干净的回购的外观,因为它超出了普通的源文件。

What should I do best? 我该怎么办?

  • it's a configuration file which maybe shouldn't made public. 它是一个配置文件,可能不应该公开。

This is wrong. 这是错的。 The POM is indeed a configuration file but it is intended for this file to be public. POM确实是一个配置文件,但它是用于公开的。 Actually, quoting Maven guide to uploading artifacts to the Central Repository : 实际上,引用Maven指南将工件上传到中央存储库

Some folks have asked why do we require all this information in the POM for deployed artifacts so here's a small explanation. 有些人问我们为什么要在POM中为部署的工件要求所有这些信息,所以这里有一个小的解释。 The POM being deployed with the artifact is part of the process to make transitive dependencies a reality in Maven. 与工件一起部署的POM是使传递依赖在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. 通过使所有POM可用于工件而实现的其他应用程序是巨大的,因此通过将它们作为流程的一部分放入存储库中,我们打开了涉及统一访问项目POM的新想法的大门。

As you see, this file is actually required so that the artifact can be uploaded to Maven Central. 如您所见,实际上需要此文件,以便可以将工件上载到Maven Central。

What should not be public is your settings, ie the settings.xml file. 不应公开的是您的设置,即settings.xml文件。 It is in this file that you should store any sensitive information, like passwords. 您应该在此文件中存储任何敏感信息,例如密码。 Again, quoting the Settings Reference (emphasis mine): 再次引用设置参考 (强调我的):

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 . settings.xml文件中的settings元素包含用于定义以各种方式配置Maven执行的值的元素,如pom.xml ,但不应捆绑到任何特定项目或分发给受众 These include values such as the local repository location, alternate remote repository servers, and authentication information. 这些包括诸如本地存储库位置,备用远程存储库服务器和身份验证信息之类的值。

If you currently store any sensitive information in your POM, you should consider refactoring it to extract this info and put it inside your settings instead. 如果您当前在POM中存储任何敏感信息,则应考虑重构它以提取此信息并将其放入您的设置中。


  • it destroys the look of a clean repo, because it's outside of the normal source files. 它破坏了一个干净的回购的外观,因为它超出了普通的源文件。

It is a source file in the sense that Maven only requirement is exactly the presence of this file. 一个源文件,Maven唯一的要求就是这个文件的存在。 It describes how to build your application and declares all of its dependencies. 它描述了如何构建应用程序并声明其所有依赖项。 To say it differently: this file is a Maven source file, and as such, should be commited along with the project main source files. 换句话说:这个文件是一个Maven源文件,因此应该与项目主源文件一起提交。 Without it, no-one can build your application and no-one can also package it. 没有它,没有人可以构建你的应用程序,没有人也可以打包它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM