我是Maven的新手,并且正在尝试开发两个项目,其中一个项目取决于另一个项目。我使用Eclipse作为我的IDE,以及它集成的Maven功能。
我们说我的两个项目名为foo
和bar
,其中bar
取决于foo
。 Eclipse可以帮助我生成以下pom.xml
s:
FOO:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.voichick</groupId>
<artifactId>foo</artifactId>
<version>0.1.0</version>
</project>
栏:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.voichick</groupId>
<artifactId>bar</artifactId>
<dependencies>
<dependency>
<groupId>com.voichick</groupId>
<artifactId>foo</artifactId>
<version>0.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<version>0.0.1</version>
</project>
当我设置这样的项目时,它似乎有效。 Eclipse中没有错误,我可以在bar
中运行依赖于foo
中的类的类。但是,仅当我使用Eclipse的Run As Java Application
选项时,此成功才适用。当我尝试将其作为Maven install
运行时,请获取以下输出:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building bar 0.0.1
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.voichick:foo:jar:0.1.0 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.201 s
[INFO] Finished at: 2017-04-30T20:25:57-05:00
[INFO] Final Memory: 8M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project bar: Could not resolve dependencies for project com.voichick:bar:jar:0.0.1: Failure to find com.voichick:foo:jar:0.1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
出于某种原因,当我从Eclipse运行foo
时,Maven似乎足够聪明地找到bar
。但是,当我尝试使用Maven构建jar时,它会失败。
我注意到,如果我将0.1.0
替换为0.1.0-SNAPSHOT
(在pom.xml
个文件中),则会成功。
我的问题是:在这种情况下Maven是如何使用的?在我准备将项目添加到中央存储库之前,我应该只使用-SNAPSHOT
个版本吗?我是否需要用模块做一些奇特的事情?或者我对Maven有一些基本的误解?