gpt4 book ai didi

Maven 项目依赖项 "could not find artifact"

转载 作者:行者123 更新时间:2023-12-03 23:56:20 24 4
gpt4 key购买 nike

我有 2 个 Maven 项目。项目 A 和项目 B。项目 B 依赖于项目 A,而不是相反。

在我的项目 B pom 中,我有这个:

    <dependency>
<groupId>com</groupId>
<artifactId>ProjectA</artifactId>
<type>pom</type>
<version>1.0-SNAPSHOT</version>
</dependency>

当我尝试打包项目时,它因以下错误而失败:
 [ERROR] Failed to execute goal on project ProjectB: Could not resolve    dependencies for project com:ProjectB:war:1.0-SNAPSHOT: Could not find  artifact com:ProjectA:pom:1.0-SNAPSHOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project ProjectB: Could not resolve dependencies for project com:ProjectB:war:1.0-SNAPSHOT: Could not find artifact com:ProjectA:pom:1.0-SNAPSHOT

所以它找不到我的 ProjectA pom。我需要把它放在我的项目中吗?它应该位于我的文件结构中的什么位置。

对于它的值(value),我使用的是 intelliJ IDE。

提前致谢。

编辑:当我在 projectA 上运行安装时,我收到此错误:
The packaging for this project did not assign a file to the build artifact

EDIT2 - 添加 ProjectA pom:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu</groupId>
<artifactId>ProjectA</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ProjectA</name>

<build>
<sourceDirectory>src/main/java</sourceDirectory>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-jar-lib</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>prepare-package</id>
<phase>prepare-package</phase>
<configuration>
<target>
<copy file="${basedir}/src/main/webapp/META-INF/context-${app.environment}.xml"
tofile="${basedir}/src/main/webapp/META-INF/context.xml" />
<copy file="${basedir}/src/main/webapp/WEB-INF/web-${app.environment}.xml"
tofile="${basedir}/src/main/webapp/WEB-INF/web.xml" />
<copy file="${basedir}/src/main/resources/log4j-${app.environment}.xml"
tofile="${basedir}/src/main/resources/log4j.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<phase>compile</phase>
<configuration>
<target>
<copy file="${project.build.directory}/classes/log4j-${app.environment}.xml"
tofile="${project.build.directory}/classes/log4j.xml" />
<delete>
<fileset dir="${project.build.directory}/classes" includes="**/*-local.*"/>
<fileset dir="${project.build.directory}/classes" includes="**/*-test.*"/>
<fileset dir="${project.build.directory}/classes" includes="**/*-prod.*"/>
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete file="${basedir}/src/main/webapp/META-INF/context.xml" />
<delete file="${basedir}/src/main/webapp/WEB-INF/web.xml" />
<tstamp>
<format property="last.timestamp" pattern="yyyyMMddHHmmss"/>
</tstamp>
<property name="build.time" value="${last.timestamp}" />
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>true</failOnMissingWebXml>
<!--<webResources>
<resource>
<directory>src/main/WEB-INF/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<filtering>false</filtering>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>-->
</configuration>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>rename-file</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${artifactId}-${version}.war</sourceFile>
<destinationFile>${project.build.directory}/ProjectA##${build.time}.war</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

最佳答案

您必须安装 ProjectA在您的本地 Maven 存储库中(或以其他方式使其在您的 pom.xml 或 settings.xml 指向的任何远程存储库中可用)。例如:

cd whereever/projectA/lives
mvn clean install

这会写 com/ProjectA/ProjectA.pom到您本地的 Maven 仓库,当您执行此操作时...
cd wherever/projectB/lives
mvn clean install

... Maven 将解析 ProjectA.pom从那个位置。

注意:您在 ProjectA 上声明的依赖项:
<dependency>
<groupId>com</groupId>
<artifactId>ProjectA</artifactId>
<type>pom</type>
<version>1.0-SNAPSHOT</version>
</dependency>

... 将传递地添加在 com:ProjectA 中声明的所有依赖项至 ProjectB的 POM,这绝对是您的意图吗?这仅在 ProjectA 时才有意义被打包为POM,如果打包为JAR则需要更新ProjectB中的依赖声明,去掉这一行: <type>pom</type> .

关于Maven 项目依赖项 "could not find artifact",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46181465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com