Maven无法解析项目的依赖关系,无法找到工件com.mycompany.app:my-app:jar:1.0-SNAP



问题描述

我正在研究一个由2个模块组成的maven项目,pageobjects-users和webdriver-tests-users,我是java新手,我不知道如何修复此错误:"未能在项目pageobject-users上执行目标:无法解决项目com.mycompany.app:pageobject-users:jar:1.0-SNAPSHOT:找不到工件com.mycompany.app:my-app:jar:1.0-SNAPSHOT;[帮助1]">

这个问题发生时,我使用mvn包或mvn包安装命令行,一切工作正常在IntelliJ IDEA

目录树
my-app
├── my-app.iml
├── pageobject-users
│   ├── pageobject-users.iml
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   ├── LandingPage.java
│   │   │   │   └── RegistrationPage.java
│   │   │   └── resources
│   │   └── test
│   │       └── java
│   └── target
│       ├── classes
│       │   ├── LandingPage.class
│       │   └── RegistrationPage.class
│       └── generated-sources
│           └── annotations
├── pom.xml
├── src
│   ├── main
│   │   └── java
│   │       └── com
│   │           └── mycompany
│   │               └── app
│   │                   ├── App.java
│   │                   └── TestRunner.java
│   └── test
│       └── java
│           └── com
│               └── mycompany
│                   └── app
│                       └── AppTest.java
├── target
│   ├── classes
│   │   └── com
│   │       └── mycompany
│   │           └── app
│   │               ├── App.class
│   │               └── TestRunner.class
│   └── test-classes
│       └── com
│           └── mycompany
│               └── app
│                   └── AppTest.class
└── webdriver-tests-users
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   └── resources
│   └── test
│       └── java
│           ├── CheckIfAccountCanBeCreated.java
│           ├── CheckIfCookiesCanBeAccepted.java
│           ├── CheckIfGOVLoginButtonWorks.java
│           ├── CheckIfRegistrationLinkWorks.java
│           ├── CheckIfStandardLoginButtonWorks.java
│           └── TestSuite.java
├── target
│   ├── generated-test-sources
│   │   └── test-annotations
│   └── test-classes
│       ├── CheckIfAccountCanBeCreated.class
│       ├── CheckIfCookiesCanBeAccepted.class
│       ├── CheckIfGOVLoginButtonWorks.class
│       ├── CheckIfRegistrationLinkWorks.class
│       ├── CheckIfStandardLoginButtonWorks.class
│       └── TestSuite.class
└── webdriver-tests-users.iml

my-app pom file:

<?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.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>pageobject-users</module>
<module>webdriver-tests-users</module>
</modules>
<name>my-app</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.3.1</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.mycompany.app</groupId>
<artifactId>pageobjects-users</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.mycompany.app</groupId>
<artifactId>webdriver-tests-users</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

pageobject-users pom file:

<?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>my-app</artifactId>
<groupId>com.mycompany.app</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pageobject-users</artifactId>
<dependencies>
<dependency>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

webdriver-tests-users pom file:

<?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>my-app</artifactId>
<groupId>com.mycompany.app</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>webdriver-tests-users</artifactId>
<dependencies>
<dependency>
<groupId>com.mycompany.app</groupId>
<artifactId>pageobject-users</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

答案

我通过创建第三个模块解决了这个问题,之后我将我的testrrun .class移动到模块并添加了对它的依赖。

最新更新