【发布时间】:2017-03-29 02:46:24
【问题描述】:
我正在尝试将 Maven 依赖项从当前的一个更改为另一个。这种其他依赖项几乎完全提供了与当前版本相同的功能,除了一些更改之外,因为当前版本是另一个旧版本的分支。为此,我有:
- 将 pom 中对旧依赖项的所有引用更改为新依赖项
- 在 Eclipse 中删除并重新导入项目
- 跑
maven clean install
但是,我仍然遇到与开始时相同的问题:
- Eclipse 看不到任何依赖类。它甚至不提供导入它们。
-
在项目上尝试
mvn clean package时,Maven 构建失败并显示以下错误消息:[ERROR] Failed to execute goal on project eet-demo-maven: Could not resolve dependencies for project cz.tomasdvorak:eet-demo-maven:jar:1.0-SNAPSHOT: Failed to collect dependencies at com.github.todvorak:eet-client:jar:1.3.2: Failed to read artifact descriptor for com.github.todvorak:eet-client:jar:1.3.2: Could not transfer artifact com.github.todvorak:eet-client:pom:1.3.2 from/to jitpack.io (https://jitpack.io): Not authorized , ReasonPhrase:Repo not found or no access token provided. -> [Help 1]
我已经检查了 pom 的拼写错误和版本的正确性,所以这些应该不是问题。我怀疑这与依赖项/依赖项管理/jitpack 以及它们的工作方式有关。我从来没有真正碰过它们。那里的所有内容要么是从我为该项目拥有的起始代码中复制而来,要么是我随后与 Maven 扭动的结果,我几乎完全是初学者。我查看了this 问题并尝试了那里的解决方案,但它们都不适用于我的情况。
如何让 Maven 再次看到依赖及其传递依赖,并正确编译项目?
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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<dontWrapJar>true</dontWrapJar>
<headerType>console</headerType>
<jar>eet-demo-maven-1.0-SNAPSHOT.jar</jar>
<outfile>target\EETSender.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>true</stayAlive>
<restartOnCrash>true</restartOnCrash>
<manifest></manifest>
<icon></icon>
<singleInstance>
<mutexName>EETMutex</mutexName>
<windowTitle></windowTitle>
</singleInstance>
<classpath>
<mainClass>cz.tomasdvorak.eetdemo.Main</mainClass>
</classpath>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.6.0_1</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>cz.tomasdvorak.eetdemo.Main</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
<groupId>cz.tomasdvorak</groupId>
<artifactId>eet-demo-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.todvorak</groupId>
<artifactId>eet-client</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.github.todvorak</groupId>
<artifactId>eet-client</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
编辑:The dependency in question on GitHub
编辑 2:我将 pom 更改如下,显然我已经安抚了 Maven 的精神,再次构建项目。 Eclipse 让我可以导入它以前看不到的所有东西。然而,对这种突然改变主意的解释仍然是对他的问题的一个有价值的结论。
<project>
.
.
.
<dependencies>
<dependency>
<groupId>com.github.todvora</groupId>
<artifactId>eet-client</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<!--
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.github.todvorak</groupId>
<artifactId>eet-client</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</dependencyManagement>
-->
</project>
【问题讨论】:
-
似乎无法下载依赖项。可能是因为权利,或者可能尚未部署。可以手动下载依赖
com.github.todvorak:eet-client:jar:1.3.2吗? -
看起来是这样。我不知道你到底是什么意思,但你可以通过 GitHub 上的“克隆或下载”按钮获取它,它位于 JitPack 按钮下。
-
那么它可能已部署,尝试使用您的 maven 设置等手动下载文件。请参阅stackoverflow.com/questions/1895492/… 了解如何调用它。如果它被下载,那么问题出在其他地方,但我有点怀疑......