【问题标题】:Eclipse doesn't see Maven dependencyEclipse 看不到 Maven 依赖项
【发布时间】:2017-03-29 02:46:24
【问题描述】:

我正在尝试将 Maven 依赖项从当前的一个更改为另一个。这种其他依赖项几乎完全提供了与当前版本相同的功能,除了一些更改之外,因为当前版本是另一个旧版本的分支。为此,我有:

  1. 将 pom 中对旧依赖项的所有引用更改为新依赖项
  2. 在 Eclipse 中删除并重新导入项目
  3. maven clean install

但是,我仍然遇到与开始时相同的问题:

  1. Eclipse 看不到任何依赖类。它甚至不提供导入它们。
  2. 在项目上尝试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/… 了解如何调用它。如果它被下载,那么问题出在其他地方,但我有点怀疑......

标签: java eclipse maven


【解决方案1】:

依赖应该是:

<dependencies>
    <dependency>
        <groupId>com.github.todvora</groupId>
        <artifactId>eet-client</artifactId>

    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.github.todvora</groupId>
            <artifactId>eet-client</artifactId>
            <version>1.3.2</version>
        </dependency>
    </dependencies>
</dependencyManagement>

你为 tordova 添加了一个额外的 k

【讨论】:

  • 是的。出于某种原因,当我转储 并将版本添加到适当的 时,它再次起作用。我想我已经习惯了自动完成和拼写检查。当我从 JitPack 复制自动生成的 pom 行以添加依赖项时,我无意中纠正了错误。
猜你喜欢
  • 1970-01-01
  • 2021-03-08
  • 2014-08-20
  • 1970-01-01
  • 1970-01-01
  • 2019-02-20
  • 2011-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多