我的整个pom构造如下:
simple-parent2-|
|-pom.xml
|-simple-model2-|
pom.xml
|-simple-weather2-|
pom.xml
simple-weather2取决于simple-model2
所以,simple-parent2 pom.xml遵循:
<?xml version="1.0" encoding="UTF-8"?>
<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>kursk.practice.ch07</groupId>
<artifactId>simple-parent2</artifactId>
<version>1.1</version>
<packaging>pom</packaging>
<name>simple-parent2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>simple-model2</module>
<module>simple-weather2</module>
<!--
<module>simple-persist2</module>
<module>simple-webapp2</module>
<module>simple-command2</module>
-->
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
simple-model2 pom.xml如下:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>kursk.practice.ch07</groupId>
<artifactId>simple-parent2</artifactId>
<version>1.1</version>
</parent>
<groupId>kursk.practice.ch07</groupId>
<artifactId>simple-model2</artifactId>
<version>1.1</version>
<packaging>jar</packaging>
<name>simple-model2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>
</dependencies>
</project>
simple-weather2 pom.xml如下所示,simple-model2是依赖项之一。
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>kursk.practice.ch07</groupId>
<artifactId>simple-parent2</artifactId>
<version>1.1</version>
</parent>
<groupId>kursk.practice.ch07</groupId>
<artifactId>simple-weather2</artifactId>
<version>1.1</version>
<name>simple-weather2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>kursk.practice.ch07</groupId>
<artifactId>simple-model2</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
首先,我安装了simple-model2,它的成功!
kursk@KURSK-PC /D/CodeSpace/maven/simple-parent2/simple-model2
$ mvn install
.....
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.445s
[INFO] Finished at: Sat Mar 08 16:22:16 CST 2014
[INFO] Final Memory: 8M/122M
[INFO] ------------------------------------------------------------------------
第二,我执行依赖:simple-weather2文件夹上的树,但是maven报告无法收集simple-model2和simple-parent2!
kursk@KURSK-PC /D/CodeSpace/maven/simple-parent2/simple-weather2
$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building simple-weather2 1.1
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.411s
[INFO] Finished at: Sat Mar 08 16:27:19 CST 2014
[INFO] Final Memory: 7M/122M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project simple-weather2: Could not resolve dependencies for project kursk.practice.ch07:simple-weather2:jar:1.1: Failed to collect de
pendencies at kursk.practice.ch07:simple-model2:jar:1.1: Failed to read artifact descriptor for kursk.practice.ch07:simple-model2:jar:1.1: Failure to find kursk.practi
ce.ch07:simple-parent2:pom:1.1 in http://dev.joget.org/archiva/repository/internal/ was cached in the local repository, resolution will not be reattempted until the up
date interval of joget-internal 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
但我可以在我的本地存储库
中找到它们kursk@KURSK-PC /C/Users/kursk/.m2/repository/kursk/practice/ch07
$ ls -l
total 0
drwxr-xr-x 4 kursk Administ 0 Mar 8 15:06 simple-model2
drwxr-xr-x 3 kursk Administ 0 Mar 8 15:07 simple-parent2
我的步骤出了什么问题?为什么maven找不到内部依赖项目?
答案 0 :(得分:0)
我没有从simple-parent2项目执行“mvn clean install”,因此simple-parent2和simple-model2 jar文件没有在本地缓存中找到。
从simple-parent2项目执行exec“mvn clean install”后,从simple-weather2项目执行“mvn dependency:tree”就行了!所以,跟随文本是从“maven-definitive-guide”中提取的
当对具有子模块的项目执行Maven时,Maven首先加载 父POM并找到所有子模块POM。然后Maven提出了所有这些 将POM投射到一个叫做Maven Reactor的东西上,分析它 模块之间的依赖关系。 Reactor负责订购组件 确保以正确的顺序编译和安装相互依赖的模块。
注意: Reactor保留POM中定义的模块顺序,除非 需要做出改变。对此有用的心理模型是图片 依赖兄弟项目的模块被“推下” 列表,直到满足依赖性排序。在极少数情况下,它 可能很方便重新排列构建的模块顺序 - 例如 如果你想要一个经常不稳定的模块朝着开始 建立。 100