无法从 Java 中的不同模块解析 class (Intellij)
Cannot resolve class from a different module in Java (Intellij)
我按以下方式构建了一个 UI 测试自动化提案:
- (parent 模块) uiTestAutomation
- (child 模块) ui-utilities
- (child 模块) ui-domain
- (child 模块) ui-tests
我希望 ui-utilities' classes 能够用于 ui-domain 和 ui-tests,以及 ui-domain 的 [=100] =]es 可以在 ui-tests.
中使用
这是我的 pom.xml 文件的样子:
parent 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-domain 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-domain</artifactId>
<groupId>ui-domain</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../ui-tests</module>
</modules>
<dependencies>
<dependency>
<groupId>ui-utilities</groupId>
<artifactId>ui-utilities</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
ui-tests 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-tests</artifactId>
<groupId>ui-tests</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>
<dependencies>
<dependency>
<groupId>ui-utilities</groupId>
<artifactId>ui-utilities</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ui-domain</groupId>
<artifactId>ui-domain</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
我在 ui-utilities 中有 BasePage class,我想在 ui-domain 中创建一个名为 LoginPage 的 class,它应该继承 BasePage。但是,我收到一条错误消息:
无法解析符号 BasePage
我在 pom.xml 文件中的依赖项方面做错了什么?
你有一个非常不寻常的 pom.xml
结构,<modules>
到处都是。 Parent pom.xml
看起来是正确的,但你不应该在子模块中使用 <modules>
除非他们有自己的子模块。
从所有子模块中删除 <modules>
部分,并使用 <dependencies>
表达模块之间的关系。
不要在子模块中更改 <groupId>
,这是没有意义的。最好是他们从 <parent>
继承这个,你可以简单地在子模块中省略 <groupId>
标签。
我再次尝试从头开始创建项目。事实证明,当从父模块创建子模块时(右键单击,添加新模块),intellij 早在定义 artifactId、groupId 的第一个弹出窗口中就自动将父模块设置为子模块。 pom 文件基本相同,并且 mvn clean install 可以无缝地用于父模块和 separatw 子模块。
现在LoginPage可以成功扩展BasePage了。
我按以下方式构建了一个 UI 测试自动化提案:
- (parent 模块) uiTestAutomation
- (child 模块) ui-utilities
- (child 模块) ui-domain
- (child 模块) ui-tests
我希望 ui-utilities' classes 能够用于 ui-domain 和 ui-tests,以及 ui-domain 的 [=100] =]es 可以在 ui-tests.
中使用这是我的 pom.xml 文件的样子:
parent 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-domain 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-domain</artifactId>
<groupId>ui-domain</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../ui-tests</module>
</modules>
<dependencies>
<dependency>
<groupId>ui-utilities</groupId>
<artifactId>ui-utilities</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
ui-tests 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-tests</artifactId>
<groupId>ui-tests</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>
<dependencies>
<dependency>
<groupId>ui-utilities</groupId>
<artifactId>ui-utilities</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ui-domain</groupId>
<artifactId>ui-domain</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
我在 ui-utilities 中有 BasePage class,我想在 ui-domain 中创建一个名为 LoginPage 的 class,它应该继承 BasePage。但是,我收到一条错误消息:
无法解析符号 BasePage
我在 pom.xml 文件中的依赖项方面做错了什么?
你有一个非常不寻常的 pom.xml
结构,<modules>
到处都是。 Parent pom.xml
看起来是正确的,但你不应该在子模块中使用 <modules>
除非他们有自己的子模块。
从所有子模块中删除
<modules>
部分,并使用<dependencies>
表达模块之间的关系。不要在子模块中更改
<groupId>
,这是没有意义的。最好是他们从<parent>
继承这个,你可以简单地在子模块中省略<groupId>
标签。
我再次尝试从头开始创建项目。事实证明,当从父模块创建子模块时(右键单击,添加新模块),intellij 早在定义 artifactId、groupId 的第一个弹出窗口中就自动将父模块设置为子模块。 pom 文件基本相同,并且 mvn clean install 可以无缝地用于父模块和 separatw 子模块。 现在LoginPage可以成功扩展BasePage了。