[英]Maven Could not resolve dependencies for project, Could not find artifact com.mycompany.app:my-app:jar:1.0-SNAPSHOT
Problem description问题描述
I'm working on a maven project which consists of 2 modules, pageobjects-users and webdriver-tests-users, I am new to java and I don't know how to fix this error: "Failed to execute goal on project pageobject-users: Could not resolve dependencies for project com.mycompany.app:pageobject-users:jar:1.0-SNAPSHOT: Could not find artifact com.mycompany.app:my-app:jar:1.0-SNAPSHOT -> [Help 1] "我正在开发一个 maven 项目,该项目由 2 个模块、pageobjects-users 和 webdriver-tests-users 组成,我是 java 的新手,我不知道如何解决此错误:“无法在项目 pageobject 上执行目标- users: Could not resolve dependencies for project com.mycompany.app:pageobject-users:jar:1.0-SNAPSHOT: Could not find artifact com.mycompany.app:my-app:jar:1.0-SNAPSHOT -> [Help 1] "
this problem occurs when I use mvn package or mvn package install commandline, everything works fine on IntelliJ IDEA当我使用 mvn package 或 mvn package 安装命令行时会出现此问题,在 IntelliJ IDEA 上一切正常
catalog tree目录树
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:我的应用程序 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">
<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:页面对象用户 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>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: webdriver-tests-users 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>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>
Answer回答
I got it solved by creating third module, after that I moved my TestRunner.class to the module and added dependency on it.我通过创建第三个模块解决了它,之后我将我的 TestRunner.class 移动到模块并添加了对它的依赖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.