【问题标题】:Maven Parent - child project issueMaven父子项目问题
【发布时间】:2016-05-09 07:20:38
【问题描述】:

我有父项目 - selenium 和子项目作为项目 1,我的意图是让所有可重用的类在父项目中并在子项目中测试。当我尝试从子项目运行测试时,出现以下错误,可以请帮帮我。”未能在项目 project1 上执行目标:无法解析项目 com.aero:project1:pom 的依赖项: 1.0-SNAPSHOT:无法解析以下工件:com.automation:parentproject:jar:1.0-SNAPSHOT”。我首先在父项目和子项目尝试 mvn clean 和 mvn install 然后执行 mvn surefire:test 但得到上述异常.
注意:当我第一次构建父项目时,它不会在 .M2 路径中生成 .jar 文件

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>com.automation</groupId>
    <artifactId>parentproject</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <modules>
        <module>project1</module>
    </modules>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-htmlunit-driver</artifactId>
            <version>2.52.0</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.10</version>
        </dependency>
             <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>3.2.1.RELEASE</version>
        </dependency>
    </dependencies>
</project>

儿童 pom:

<?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">
    <parent>
        <artifactId>selenium</artifactId>

        <groupId>com.automation</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>    <modelVersion>4.0.0</modelVersion>

    <artifactId>project1</artifactId>
    <packaging>pom</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.automation</groupId>
            <artifactId>parentproject</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>


</project>

【问题讨论】:

  • 在 pom.xml 上面提到过

标签: maven


【解决方案1】:

1- 你的孩子 pom 引用了错误的父工件。

2- 应该删除对“parentproject”的直接依赖,因为它的父项而不是依赖项。

家长:

<?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>com.automation</groupId>
<artifactId>parentproject</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<modules>
    <module>project1</module>
</modules>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
    </dependency>
    <dependency><--!You are not using the Java bindings (i.e. Python, C#, or Ruby) and would like to use HtmlUnit Driver-->
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-htmlunit-driver</artifactId>
        <version>2.52.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
        <scope>test</scope>
    </dependency>
         <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>3.2.1.RELEASE</version>
    </dependency>
</dependencies>

孩子:

<?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">
<parent>
    <artifactId>parentproject</artifactId>

    <groupId>com.automation</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>    <modelVersion>4.0.0</modelVersion>

<artifactId>project1</artifactId>
<packaging>pom</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
       ...
    </dependency>
</dependencies>

希望对你有帮助

【讨论】:

  • test 已在子项目中提及,但问题仍然相同
  • 是的,我已经更新了 child pom,你可以看看
  • 正如我所见,上部 pom 不是下部 pom 的父级。子 pom 的父级应该是“parentproject”。这个工件“selenium”来自哪里?
  • 抱歉,Hisham 我刚刚重命名了项目,因为它是保密的,我错误地提到了。但这是我的方案,请看一下
  • 如果我删除“对“父项目”的直接依赖项,那么我如何将可重用从父项扩展到子项。如果我悬停它说添加父项依赖项,我使用 intellij ide,如果这样做我可以扩展子项目中的类。但是我如何在不添加依赖项的情况下引用父项目中的类。请帮助我
猜你喜欢
  • 1970-01-01
  • 2014-03-28
  • 2011-03-01
  • 2019-12-22
  • 1970-01-01
  • 1970-01-01
  • 2020-11-05
  • 1970-01-01
  • 2011-06-12
相关资源
最近更新 更多