Maven如何满足在pom.xml中定义的GroupID:Artifact依赖关系?

huangapple go评论61阅读模式
英文:

How does Maven satisfy GroupID:Artifact dependencies defiend in the pom.xml?

问题

I have been passed a maven project without much documentation and while trying to compile it with "mvn compile" i am running into this error:

Could not resolve dependencies for project de.companyName:tcui-web:war:2.1.0: Could not find artifact de.companyName:spring-commons-config:jar:0.0.1-SNAPSHOT ... 

The META-INF/MANIFEST.MF file doesn't seem to give me any clues as to where the dependency could be satisfied from.

What possible ways does MVN give me to locate those dependencies and satisfy them manually?

Apart from the manifest file, where could i find specific urls / paths to the dependencies?

Am I maybe approaching this issue from a completely incorrect direction due to my lack of knowledge about java?

英文:

I have been passed a maven project without much documentation and while trying to compile it with "mvn compile" i am running into this error:

Could not resolve dependencies for project de.companyName:tcui-web:war:2.1.0: Could not find artifact de.companyName:spring-commons-config:jar:0.0.1-SNAPSHOT ... 

The META-INF/MANIFEST.MF file doesn't seem to give me any clues as to where the dependency could be satisfied from.

    Manifest-Version: 1.0
Implementation-Title: TCUI
Implementation-Version: test-version
Built-By: REDACTED
Created-By: Apache Maven 3.2.3
Implementation-URL: tc.company.de
url: tc.company.de
version: test-version
mode: development
Implementation-Vendor: Company
revision: test-revision
Implementation-Vendor-Id: de.company
Build-Jdk: 1.7.0_67
Archiver-Version: Plexus Archiver
bambooBuild: 000

What possible ways does MVN give me to locate those dependencies and satisfy them manually?

Apart from the manifest file, where could i find specific urls / paths to the dependencies?

Am I maybe approaching this issue from a completely incorrect direction due to my lack of knowledge about java?

答案1

得分: 2

Maven通过在一个或多个仓库中查找依赖项来解析它们。Maven仓库是一个包含构件(通常是带有一些元数据的jar文件)的存档。默认情况下,Maven将使用Maven Central仓库,这是一个包含大多数流行的开源库的公共仓库。根据您特定依赖项的名称de.companyName:tcui-web:war:2.1.0可能是一个内部闭源依赖项,而不是公共依赖项。这意味着它不存储在Maven Central中,这就是为什么您收到该错误的原因。Maven正在寻找您的构件,但可能在错误的位置。那么您如何解决这个问题?有两个选项:

  1. 您的客户组织拥有自己的内部Maven仓库,其中包含内部开发或已获取的构件。如果是这样,您需要请求该仓库的URL(可能还需要凭据),然后配置您的本地Maven安装,使其使用您公司的内部Maven仓库来解析依赖项。这通常是组织内部处理内部构件的首选方式。
  2. 如果您可以访问jar文件,您可以手动将其安装到本地Maven仓库中。每台安装了Maven的计算机都有自己的本地仓库。这就是Maven的工作方式。它首先查询本地仓库,然后如果构件不存在,它将查询远程仓库(可以是Maven Central或由您的组织提供的仓库)并拉取一个副本以使其在本地可用。但您可以通过直接将构件安装到本地仓库来绕过此过程。这通常不建议,因为您必须在每台开发机器和构建服务器上重复此步骤。当然,您可以编写脚本来执行此操作,但此时建议设置一个自定义Maven仓库,因为这样做非常简单。
英文:

Maven resolves dependencies by looking them up in one or more repositories. A Maven repository is an archive containing artifacts (usually jar files with some metadata). By default, Maven will use the Maven Central repository, which is a public repository that contains most popular open source libraries. Judging by the name of your specific dependency de.companyName:tcui-web:war:2.1.0 is probably an internal closed-source dependency, rather than a public one. This means it is not stored in Maven Central, which is why you're receiving that error. Maven is looking for your artifact but probably in the wrong place. So how do you solve this? There are two options:

  1. Your client's organization has its own internal Maven repository that contains internally developed or acquired artifacts. If so you need to ask for the url (and possibly credentials) of this repository and configure your local Maven installation so it will use your company's internal Maven repository to resolve dependencies. This is usually the preferred way to handling internal artifacts within an organization.
  2. If you have access to the jar file, you can install it manually in your local Maven repository. Every machine with Maven installed has its own local repository. That's how Maven works. It first queries the local repository, then if the artifact is not there it will query a remote repository (which can be Maven Central or one provided by your organization) and pull in a copy so it's available locally. But you can bypass this by installing artifacts directly into your local repository. This is usually not recommended since you have to repeat this step on every development machine and build server. Of course you could script this but at that point it'd probably be easier to setup a custom Maven repository since it's quite simple to do so.

huangapple
  • 本文由 发表于 2020年7月29日 02:40:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/63140784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定