我应该在pom.xml中编写存储库吗? [英] Should I write repositories in my pom.xml?

查看:70
本文介绍了我应该在pom.xml中编写存储库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Maven的新手.如果我从Maven开始新项目,我是否应该知道任何可以使用它的存储库URL?

I am new to Maven. If I start new project with Maven, should I know any repository URLs for it to work?

例如,此Hibernate教程 http://docs.jboss.org/hibernate/core/3.3/reference/zh-CN/html/tutorial.html 介绍了如何使用pom.xml文本创建示例项目.但是此pom.xml不包含任何存储库.

For example, this Hibernate tutorial http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html says about how to create a sample project with pom.xml text. But this pom.xml does not contain any repositories.

所以,我的m2eclipse插件说,例如 Project build error:org.hibernate:hibernate-core:jar的'dependencies.dependency.version'丢失.,对于pom中的所有依赖项标签.xml

So, my m2eclipse plugin says, for example Project build error: 'dependencies.dependency.version' for org.hibernate:hibernate-core:jar is missing., for all dependency tag in pom.xml

这是因为缺少存储库吗?

Is this because of repositories absence?

在哪里知道存储库URL?有一个大仓库吗?为什么默认不包含它?

Where to know repositories URLs? Is there one big repository? Why doesn't it included by default?

更新1 这里说,Maven默认使用中央"存储库: http://maven.apache.org/guides/introduction/introduction-to-repositories.html

UPDATE 1 It is said here, that Maven should use "central" repository by default: http://maven.apache.org/guides/introduction/introduction-to-repositories.html

我在那里搜索了休眠代码工件,并找到了它.因此,此工件位于中央存储库中.据我的专家说,没有找到依赖关系.因此,它不使用它的中央存储库.为什么?

I have searched there for hibernate-code artifact and found it. So, this artifact IS in central repository. By my maven says dependency not found. Hence it doesn't use it's central repository. Why?

推荐答案

显然您的Hibernate依赖项缺少< version> 标记:

Apparently your Hibernate dependency is missing <version> tag:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.6.9.Final</version> <!-- this line is missing -->
</dependency>

请注意,您不必指定先前在中声明的依赖项版本.< dependencyManagement> .

Note that you don't have to specify version of dependencies previously declared in <dependencyManagement>.

每个构建脚本(不仅限于Maven)都应具有可复制性,并且与环境无关.标准pom.xml (称为 super pom ),每个 pom.xml 都继承自此,已经定义了主要的Maven中央存储库:

Every build script (not only with Maven) should be reproducible and independent from environment. Standard pom.xml (called super pom), which every pom.xml inherits from, already defines main Maven central repository:

<repositories>
  <repository>
    <id>central</id>
    <name>Maven Repository Switchboard</name>
    <layout>default</layout>
    <url>http://repo1.maven.org/maven2</url>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
</repositories>

如果所有依赖项都存在,则不必定义此存储库,也不必定义任何其他存储库.另一方面,如果您正在使用某些外部存储库,则必须将它们添加到 pom.xml 中,以便每个开发人员始终能够进行构建.

You don't have to define this repository and you don't have to define any others if all your dependencies are there. On the other hand if you are using some external repositories, you must add them to pom.xml, so that every developer is always able to build.

最重要的是:如果您可以构建具有完全空的存储库的项目,则您的 pom.xml 很好.

The bottom line is: if you can build the project having completely empty repository, your pom.xml is fine.

这篇关于我应该在pom.xml中编写存储库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆