具有多模块的 Maven 项目无法找到 pom.xml 个模块 - Jenkins/Eclipse

Maven Project with multi modules is unable to find pom.xml of modules - Jenkins/Eclipse

我在 Jenkins 上创建了一个 Maven 项目,它将从 Butbucket 克隆一个 mercurial 分支,所以我可以 运行 我的 Selenium TestNG 脚本。我曾尝试清除工作区以获得干净的构建,但它导致了与以前相同的错误。此外,我检查了我的 jenkins 工作区中每个模块的 pom.xml 文件,它们都存在。单击来自控制台的错误报告的图像。我不明白为什么 Jenkins 和 Eclipse 在同一个项目文件夹中时都找不到我的依赖项的 pom.xml 文件。

Image: Jenkins Console Output

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>

<parent>
    <artifactId>PSWebTestFramework</artifactId>
    <groupId>com.guidewire.pstesting</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

<artifactId>pswtf-test-tp-pc</artifactId>

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.21</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
    </dependency>
    <dependency>
        <groupId>com.guidewire.pstesting</groupId>
        <artifactId>pswtf-application-core</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.guidewire.pstesting</groupId>
        <artifactId>pswtf-test-core</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.guidewire.pstesting</groupId>
        <artifactId>pswtf-test-tp-core</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.guidewire.pstesting</groupId>
        <artifactId>pswtf-application-tp-pc</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.guidewire.pstesting</groupId>
        <artifactId>pswtf-application-ootb-pc</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

<build>
    <defaultGoal>test</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <excludes>META-INF/*.SF</excludes>
                <excludes>META-INF/*.DSA</excludes>
                <excludes>META-INF/*.RSA</excludes>
                <argLine>-Dorg.uncommons.reportng.escape-output=false</argLine>   <!-- get html in reports rather than string -->
                <properties>
                    <property>
                        <name>usedefaultlisteners</name>
                        <value>false</value> <!-- disabling default listeners is optional -->
                    </property>
                    <property>
                        <name>listener</name>
                        <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter, org.testng.reporters.XMLReporter</value>
                    </property>
                </properties>
                <additionalClasspathElements>
                    <additionalClasspathElement>${basedir}/src/test/conf</additionalClasspathElement>
                    <additionalClasspathElement>${basedir}/src/test/testdata</additionalClasspathElement>
                </additionalClasspathElements>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

更新: 基于下面的解决方案,我改变了我的工作配置并根据下面的图片,我能够获得成功而不是失败。

Image: Job Configuration

您附加的屏幕截图中的错误意味着工件 ID "pswtf-test-tp-pc" 无法在本地 Maven 存储库中找到依赖项。

使用 Maven <modules> 标签从父 POM 构建所有项目。在具有工件 ID PSWebTestFramework 的父文件夹中的 pom.xml 中添加它。 运行 首先是这个父 pom,然后是你的项目 - pswtf-test-tp-pc

<modules>
    <module>pswtf-application-core</module>
    <module>pswtf-test-core</module>
    <module>pswtf-test-tp-core</module>
    <module>pswtf-application-tp-pc</module>
</modules>

这应该构建每个模块并将其安装在本地 Maven 存储库中。

P.S。 - 使用 mvn clean install 命令在本地仓库中安装依赖项。