如何创建一个建设者项目

时间:2019-07-31 20:02:46

标签: java maven maven-3

我有一个class compare{ private $array1; private $array2; public function __construct($mile1, $mile2){ $this->array1 = $mile1->milearray; $this->array2 = $mile2->milearray; } public function comparemile(){ // code that compares $this->$array1 and $this->$array2 } } 项目和两个parent / child-1项目。在我的磁盘上,所有共享相同的父目录:

child-2

为了尽量减少工作异常,请考虑以下/my-project /parent /child-1 /child-2

父级

pom.xml

child-1

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

    <groupId>com.test</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
</project>

child-2

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

    <parent>
        <groupId>com.test</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>child-1</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
</project>

问题

<?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.test</groupId> <artifactId>parent</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <artifactId>child-2</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> </project> 项目中,我故意不包括以下模块定义:

parent

这样做的原因是我想独立于子项目构建父项。每当父项目更改时,Jenkins都会自动重建所有子项目。

在我的开发机器上,如果我可以重建整个项目,这将很有用。也就是说,首先<modules> <module>child-1</module> <module>child-2</module> </modules> ,然后是parentchild-1。我可以在所有3个目录中调用child-2,但这很麻烦。请注意,在实际情况下,有更多的mvn compile项目,并且它们之间存在依赖性。因此,我将必须在项目依赖关系图中构建与它们的拓扑排序相对应的每个child项目。

所以我考虑过引入一个child项目,如下所示:

builder
/my-project
    /parent
    /child-1
    /child-2
    /builder

现在,当我在<?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.test</groupId> <artifactId>builder</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>../parent</module> <module>../child-1</module> <module>../child-2</module> </modules> </project> 目录中调用mvn compile时,我得到:

builder

那是为什么?如何解决?我对这个[ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for com.test:child-1:1.0.0-SNAPSHOT: Could not find artifact com.test:parent:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 [FATAL] Non-resolvable parent POM for com.test:child-2:1.0.0-SNAPSHOT: Could not find artifact com.test:parent:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 @ [ERROR] The build could not read 2 projects -> [Help 1] [ERROR] [ERROR] The project com.test:child-1:1.0.0-SNAPSHOT (/home/ebbe/my-project/child-1/pom.xml) has 1 error [ERROR] Non-resolvable parent POM for com.test:child-1:1.0.0-SNAPSHOT: Could not find artifact com.test:parent:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2] [ERROR] [ERROR] The project com.test:child-2:1.0.0-SNAPSHOT (/home/ebbe/my-project/child-2/pom.xml) has 1 error [ERROR] Non-resolvable parent POM for com.test:child-2:1.0.0-SNAPSHOT: Could not find artifact com.test:parent:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2] 项目的想法完全可能吗?

0 个答案:

没有答案