2017-12-18 205 views
-1

我是Maven新手,所以我想知道为什么Maven会真正下载父母。Maven母公司POM下载

这里是我的样本目录:

├── hazriq-module 
│ ├── document-generator 
│ |  ├── src folder 
│ |  └── pom.xml (document-generator) 
│ └── pom.xml (hazriq-module) 
└── pom.xml (hazriq-parent) 

我hazriq父母.pom文件:

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.hazriq</groupId> 
    <artifactId>hazriq-parent</artifactId> 
    <version>${hazriq.verion}</version> 
    <packaging>pom</packaging> 

    <properties> 
    <hazriq.verion>1.0.0</hazriq.verion> 
    </properties> 

    <modules> 
     <module>hazriq-module</module> 
    </modules> 
</project> 

我hazriq模块.pom文件:

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.hazriq</groupId> 
     <artifactId>hazriq-parent</artifactId> 
     <version>1.0.0</version> 
    <relativePath>../pom.xml</relativePath> 
    </parent> 

    <artifactId>hazriq-module</artifactId> 
    <name>hazriq-module</name> 
    <packaging>pom</packaging> 
    <version>${hazriq.verion}</version> 

    <modules> 
     <module>document-generator</module> 
    </modules> 
</project> 

我的文档 - 发电机.pom文件:

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.hazriq</groupId> 
     <artifactId>hazriq-module</artifactId> 
     <version>1.0.0</version> 
     <relativePath>../pom.xml</relativePath> 
    </parent> 

    <groupId>com.hazriq.hazriq-module</groupId> 
    <artifactId>document-generator</artifactId> 

    <dependencies> 
     ... 
    </dependencies> 

当我尝试运行mvn install

$ mvn install 
[INFO] Scanning for projects... 
[ERROR] The build could not read 1 project -> [Help 1] 
[ERROR] 
[ERROR] The project com.hazriq:hazriq-module:${hazriq.verion} (C:\development\hzrqmvn\hazriq-module\pom.xml) has 1 error 
[ERROR]  Non-resolvable parent POM: Failure to find com.hazriq:hazriq-parent:pom:1.0.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 and 'parent.relativePath' points at wrong local POM @ line 3, column 10 -> [Help 2] 
[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/ProjectBuildingException 
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException 

我的问题是:1。 为什么会真正Maven的去尝试下载hazriq-parent?从repo.maven.apache.org? (请参阅上面我的mvn clean install的输出 2.如何成功构建我的项目?

回答

0

为什么不这样做?如果构建模块,则必须递归解析其所有父模块。所有的依赖。

这意味着这些文物必须是无论是在配置的远程存储库(Maven的中央默认情况下)或当地的一个。你可以做一个mvn install它添加到你的本地仓库。

+0

这是一个新的回购,所以我没有任何我的远程回购任何artefact尚未。尽管我尝试过'mvn install',但你可以看到我在上面的问题中提到了错误。 –

+0

@HazriqIshak你必须首先对父进行'mvn install'。 –

+0

是的。我做了,但它给我一个错误。它的问题。 –

0

原因我的一个失败是因为占位符在<version>

我改变了我的父母.pom到:

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.hazriq</groupId> 
    <artifactId>hazriq-parent</artifactId> 
    <version>1.0.0</version> 
    <packaging>pom</packaging> 

    <modules> 
     <module>hazriq-module</module> 
    </modules> 
</project> 

我模块.pom:

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.hazriq</groupId> 
     <artifactId>hazriq-parent</artifactId> 
     <version>1.0.0</version> 
    <relativePath>../pom.xml</relativePath> 
    </parent> 

    <artifactId>hazriq-module</artifactId> 
    <name>hazriq-module</name> 
    <packaging>pom</packaging> 
    <version>1.0.0</version> 

    <modules> 
     <module>document-generator</module> 
    </modules> 
</project> 

我的文档生成.pom:

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
     <groupId>com.hazriq</groupId> 
     <artifactId>hazriq-module</artifactId> 
     <version>1.0.0</version> 
    </parent> 

    <groupId>com.hazriq.hazriq-module</groupId> 
    <artifactId>document-generator</artifactId> 


</project> 

在这个问题上很好看的: https://jeanchristophegay.com/maven-unique-version-multi-modules-build-en/