为了账号安全,请及时绑定邮箱和手机立即绑定

无法从 Java 中的不同模块解析类 (Intellij)

无法从 Java 中的不同模块解析类 (Intellij)

呼如林 2024-01-28 16:30:36
我通过以下方式构建了 UI 测试自动化提案:(父模块)uiTestAutomation(子模块)ui-utilities(子模块)ui-domain(子模块)ui 测试我希望 ui-utilities 的类能够在 ui-domain 和 ui-tests 中使用,并且 ui-domain 的类也能够在 ui-tests 中使用。我的 pom.xml 文件如下所示:父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>uiTestAutomation</groupId>    <artifactId>uiTestAutomation</artifactId>    <packaging>pom</packaging>    <version>1.0-SNAPSHOT</version>    <modules>        <module>ui-utilities</module>        <module>ui-tests</module>        <module>ui-domain</module>    </modules></project>ui-utilities 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">    <parent>        <artifactId>uiTestAutomation</artifactId>        <groupId>uiTestAutomation</groupId>        <version>1.0-SNAPSHOT</version>    </parent>    <modelVersion>4.0.0</modelVersion>    <artifactId>ui-utilities</artifactId>    <groupId>ui-utilities</groupId>    <version>1.0-SNAPSHOT</version>    <packaging>pom</packaging>    <build>        <plugins>            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-compiler-plugin</artifactId>                <configuration>                    <source>8</source>                    <target>8</target>                </configuration>            </plugin>        </plugins>    </build>    <modules>        <module>../ui-domain</module>        <module>../ui-tests</module>    </modules></project>我在 ui-utilities 中有 BasePage 类,我想在 ui-domain 中创建一个名为 LoginPage 的类,它应该继承 BasePage。但是,我收到一条错误消息:无法解析符号 BasePage就 pom.xml 文件中的依赖关系而言,我做错了什么?
查看完整描述

2 回答

?
拉莫斯之舞

TA贡献1820条经验 获得超10个赞

你有一个非常不寻常的pom.xml结构,<modules>到处都指向。父级pom.xml看起来正确,但您不应该<modules>在子模块中使用,除非它们有自己的子模块。

  1. <modules>从所有子模块中删除该部分并用于<dependencies>表达模块之间的关系。

  2. 不要<groupId>在子模块中进行更改,这是没有意义的。最好是他们从 继承它,并且您可以简单地在子模块中<parent>省略标签。<groupId>


查看完整回答
反对 回复 2024-01-28
?
DIEA

TA贡献1820条经验 获得超2个赞

我再次尝试从头开始创建该项目。事实证明,当从父模块创建子模块时(右键单击,添加新模块),intellij 早在定义 artifactId、groupId 的第一个弹出窗口时就自动将父模块设置为子模块。pom 文件基本相同,并且 mvn clean install 对于父模块和单独的子模块都可以无缝工作。现在LoginPage可以成功扩展BasePage。



查看完整回答
反对 回复 2024-01-28
  • 2 回答
  • 0 关注
  • 83 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信