下载的项目中缺少依赖项。

huangapple go评论85阅读模式
英文:

missing dependencies in downloaded project

问题

我尝试使用项目 https://github.com/castor-software/decompilercmp。我从 Git 下载了它,注意到它是一个 Maven 项目,安装了 Maven,然后尝试运行:

    mvn install
但是得到了以下输出:

    [INFO] 正在扫描项目...
    [WARNING] 
    [WARNING] 在构建 se.kth:decompiler-cmp:jar:1.0-SNAPSHOT 的有效模型时遇到了一些问题
    [WARNING] 'dependencies.dependency.systemPath' 中的 scala:jardiff:jar 不应该指向项目目录内的文件,${basedir}/lib/jardiff.jar 将无法被依赖项目解析 @ line 34, column 25
    [WARNING] 'dependencies.dependency.systemPath' 中的 jd:jd-core:jar 不应该指向项目目录内的文件,${basedir}/lib/jd-core-1.0.0.jar 将无法被依赖项目解析 @ line 42, column 25
    [WARNING] 'dependencies.dependency.systemPath' 中的 jadx:jadx-cli:jar 不应该指向项目目录内的文件,${basedir}/lib/jadx-0.9.0/lib/jadx-cli-0.9.0.jar 将无法被依赖项目解析 @ line 50, column 25
    [WARNING] 'dependencies.dependency.systemPath' 中的 cli.jd:jd-gui:jar 不应该指向项目目录内的文件,${basedir}/lib/jd-gui-1.4.1.jar 将无法被依赖项目解析 @ line 58, column 25
    [WARNING] 'dependencies.dependency.systemPath' 中的 org.jode:jode-decompiler:jar 不应该指向项目目录内的文件,${basedir}/lib/jode-1.1.2-pre1.jar 将无法被依赖项目解析 @ line 65, column 25
    [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' 必须是唯一的:fr.inria.gforge.spoon:spoon-core:jar -> 版本 7.3.0 vs 7.5.0 @ line 163, column 21
    [WARNING] 'dependencies.dependency.systemPath' 中的 scala:jardiff:jar 指向一个不存在的文件 /Users/shlomiagiv/work/decompilercmp/lib/jardiff.jar @ line 34, column 25
    [WARNING] 'dependencies.dependency.systemPath' 中的 jd:jd-core:jar 指向一个不存在的文件 /Users/shlomiagiv/work/decompilercmp/lib/jd-core-1.0.0.jar @ line 42, column 25
    [WARNING] 'dependencies.dependency.systemPath' 中的 jadx:jadx-cli:jar 指向一个不存在的文件 /Users/shlomiagiv/work/decompilercmp/lib/jadx-0.9.0/lib/jadx-cli-0.9.0.jar @ line 50, column 25
    [WARNING] 'dependencies.dependency.systemPath' 中的 cli.jd:jd-gui:jar 指向一个不存在的文件 /Users/shlomiagiv/work/decompilercmp/lib/jd-gui-1.4.1.jar @ line 58, column 25
    [WARNING] 'dependencies.dependency.systemPath' 中的 org.jode:jode-decompiler:jar 指向一个不存在的文件 /Users/shlomiagiv/work/decompilercmp/lib/jode-1.1.2-pre1.jar @ line 65, column 25
    [WARNING] 
    [WARNING] 强烈建议解决这些问题,因为它们会威胁到构建的稳定性。
    [WARNING] 
    [WARNING] 因此,未来的 Maven 版本可能不再支持构建此类格式不正确的项目。
    [WARNING] 
    [INFO] 
    [INFO] -----------------------< se.kth:decompiler-cmp >------------------------
    [INFO] 正在构建 decompiler-cmp 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] 构建失败
    [INFO] ------------------------------------------------------------------------
    [INFO] 总时间:  0.483 秒
    [INFO] 完成于: 2020-05-03T08:13:12+03:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] 无法执行项目 decompiler-cmp 的目标: 无法解析项目 se.kth:decompiler-cmp:jar:1.0-SNAPSHOT 的依赖项: 以下构件无法被解析:scala:jardiff:jar:1.2.0, jd:jd-core:jar:1.0.0, jadx:jadx-cli:jar:0.9.0, cli.jd:jd-gui:jar:1.4.1, org.jode:jode-decompiler:jar:1.2.1-pre1:无法在指定路径 /Users/shlomiagiv/work/decompilercmp/lib/jardiff.jar 找到构件 scala:jardiff:jar:1.2.0 -> [帮助 1]
    [ERROR] 
    [ERROR] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。
    [ERROR] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。
    [ERROR] 
    [ERROR] 有关错误和可能的解决方案的更多信息,请阅读以下文章:
    [ERROR]

 [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

这些缺失的依赖项是项目试图访问的各种反编译器。我该如何获取/指向它们?请注意,我正在使用 MacOS。

例如 jadx 的 pom.xml 条目:

    <dependency>
         <groupId>jadx</groupId>
         <artifactId>jadx-cli</artifactId>
         <version>0.9.0</version>
         <scope>system</scope>
         <systemPath>${basedir}/lib/jadx-0.9.0/lib/jadx-cli-0.9.0.jar</systemPath>
    </dependency&gt

<details>
<summary>英文:</summary>

I&#39;m trying to use project https://github.com/castor-software/decompilercmp. I downloaded from git, noticed it&#39;s a maven project, installed maven, then tried to do:

    mvn install
and got:

    [INFO] Scanning for projects...
    [WARNING] 
    [WARNING] Some problems were encountered while building the effective model for se.kth:decompiler-cmp:jar:1.0-SNAPSHOT
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for scala:jardiff:jar should not point at files within the project directory, ${basedir}/lib/jardiff.jar will be unresolvable by dependent projects @ line 34, column 25
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for jd:jd-core:jar should not point at files within the project directory, ${basedir}/lib/jd-core-1.0.0.jar will be unresolvable by dependent projects @ line 42, column 25
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for jadx:jadx-cli:jar should not point at files within the project directory, ${basedir}/lib/jadx-0.9.0/lib/jadx-cli-0.9.0.jar will be unresolvable by dependent projects @ line 50, column 25
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for cli.jd:jd-gui:jar should not point at files within the project directory, ${basedir}/lib/jd-gui-1.4.1.jar will be unresolvable by dependent projects @ line 58, column 25
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for org.jode:jode-decompiler:jar should not point at files within the project directory, ${basedir}/lib/jode-1.1.2-pre1.jar will be unresolvable by dependent projects @ line 65, column 25
    [WARNING] &#39;dependencies.dependency.(groupId:artifactId:type:classifier)&#39; must be unique: fr.inria.gforge.spoon:spoon-core:jar -&gt; version 7.3.0 vs 7.5.0 @ line 163, column 21
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for scala:jardiff:jar refers to a non-existing file /Users/shlomiagiv/work/decompilercmp/lib/jardiff.jar @ line 34, column 25
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for jd:jd-core:jar refers to a non-existing file /Users/shlomiagiv/work/decompilercmp/lib/jd-core-1.0.0.jar @ line 42, column 25
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for jadx:jadx-cli:jar refers to a non-existing file /Users/shlomiagiv/work/decompilercmp/lib/jadx-0.9.0/lib/jadx-cli-0.9.0.jar @ line 50, column 25
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for cli.jd:jd-gui:jar refers to a non-existing file /Users/shlomiagiv/work/decompilercmp/lib/jd-gui-1.4.1.jar @ line 58, column 25
    [WARNING] &#39;dependencies.dependency.systemPath&#39; for org.jode:jode-decompiler:jar refers to a non-existing file /Users/shlomiagiv/work/decompilercmp/lib/jode-1.1.2-pre1.jar @ line 65, column 25
    [WARNING] 
    [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
    [WARNING] 
    [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
    [WARNING] 
    [INFO] 
    [INFO] -----------------------&lt; se.kth:decompiler-cmp &gt;------------------------
    [INFO] Building decompiler-cmp 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  0.483 s
    [INFO] Finished at: 2020-05-03T08:13:12+03:00
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project decompiler-cmp: Could not resolve dependencies for project se.kth:decompiler-cmp:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: scala:jardiff:jar:1.2.0, jd:jd-core:jar:1.0.0, jadx:jadx-cli:jar:0.9.0, cli.jd:jd-gui:jar:1.4.1, org.jode:jode-decompiler:jar:1.2.1-pre1: Could not find artifact scala:jardiff:jar:1.2.0 at specified path /Users/shlomiagiv/work/decompilercmp/lib/jardiff.jar -&gt; [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR]

 [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

those missing dependencies are various decompilers the project is trying to reach.
How do I get/point to them? Note that I&#39;m using MacOS

example pom.xml entry for jadx:

    &lt;dependency&gt;
         &lt;groupId&gt;jadx&lt;/groupId&gt;
         &lt;artifactId&gt;jadx-cli&lt;/artifactId&gt;
         &lt;version&gt;0.9.0&lt;/version&gt;
         &lt;scope&gt;system&lt;/scope&gt;
         &lt;systemPath&gt;${basedir}/lib/jadx-0.9.0/lib/jadx-cli-0.9.0.jar&lt;/systemPath&gt;
    &lt;/dependency&gt;


</details>


# 答案1
**得分**: 4

一般来说,Maven 使用远程仓库的概念(例如 [Maven Central][1])来查找项目的依赖关系并将它们存储在本地仓库缓存中(默认为 ~/.m2 文件夹)。如果需要的话,你也可以添加自己的远程仓库。

然而,如果在系统范围内定义了一个依赖关系,这意味着你告诉 Maven 该 JAR 文件不在仓库中,而是由**你自己**提供在**你指定的文件夹**中(`systemPath`)。这种方法实际上绕过了 Maven 依赖解析机制,通常不应在真实项目中使用。相反,你应该安装像 [Nexus][2] 或者 [Artifactory][3] 这样的特殊产品,它们充当远程代理,可以托管你自己的 JAR 文件。

*那么为什么要使用系统范围呢?*

通常情况下,不应该使用它,只有在你有一些无法发布到远程仓库的 JAR 文件(例如你公司的商业私有构件),并且你没有 Nexus/Artifactory 或者不想安装它们时(例如,你是一个在本地机器上运行项目的开发者),才考虑使用系统范围。

如果你决定无论如何都使用系统范围,那么你需要**自己负责**将这些依赖关系提供给 Maven,因此你可能需要自己找到这些构件。一旦你知道 JAR 文件的位置,你可以将它们复制到 `systemPath` 指定的文件夹中,并继续绕过 Maven 的依赖解析机制。

另一种(可以说是稍微更好一些的)方法是完全不使用系统范围,一旦找到了这些 JAR 文件,使用 `mvn install:install-file` 命令将文件安装到本地仓库缓存中(~/.m2 文件夹)。你可以指定组 ID、构件 ID 和版本,它将把这个 JAR 文件存储在正确的位置。然后你就可以将这个 JAR 文件当作普通的 Maven 依赖来引用了。

这个 [链接][4] 是一个教程,展示了如何使用这些“第三方”JAR 文件。

  [1]: https://search.maven.org/
  [2]: https://www.sonatype.com/product-nexus-repository
  [3]: https://jfrog.com/artifactory/
  [4]: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

<details>
<summary>英文:</summary>

In general, maven uses the concept of remote repostories (like [maven central][1]) to look up the dependencies of your project and store them in local repository cache (~/.m2 by default). 
You can add your own remote repositories if you want.


If you define a dependency in the system scope however, this means that you instruct maven that the jar is not in a repository and instead its up to *you* to provide it in the folder that *you* specify (`systemPath`). This method effectively bypasses the maven dependency resolution mechanism and in general should not be used for real projects. Instead one should install special products like [Nexus][2] or [Artifactory][3] that serve as a remote proxy and can host your own JARs as well.


*Why should system scope be used at all?*

Usually it shouldn&#39;t, consider using it only if you have jars that cannot be published to remote repository (your private company&#39;s commercial artifacts) and you don&#39;t have a nexus/artifactory and don&#39;t want to install it (if you&#39;re 1 developer that runs stuff on your local machine or something)


If you decide to use the system scope anyway, you&#39;re by yourself responsible for &quot;providing&quot; these dependencies to maven, so you should probably find these artifacts by yourself. Once you know where the jars, you can copy them to the folder specified in the `systemPath` and keep bypassing maven&#39;s dependency resolution mechanism.

Another (arguably somewhat better approach) is to stop using system scope at all and once you&#39;ve found the jars, use mvn install:install-file command to install the file to the local repository cache (~/.m2). You&#39;ll be able to specify group id, artifact id, version, and it will store this jar in the correct place. Then you&#39;ll be able to refer this jar as a regular maven dependency.

This [Link][4] is for tutorial that shows how to work with these &quot;3rd party&quot; jars.


  [1]: https://search.maven.org/
  [2]: https://www.sonatype.com/product-nexus-repository
  [3]: https://jfrog.com/artifactory/
  [4]: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

</details>



huangapple
  • 本文由 发表于 2020年5月3日 13:21:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/61569966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定