使用maven的“LATEST”关键字在leiningen项目 [英] Using maven's "LATEST" keyword in leiningen project

查看:1514
本文介绍了使用maven的“LATEST”关键字在leiningen项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个leiningen项目。根据此问题,maven应该允许我使用LATEST作为依赖性版本。它给我一个错误,建议不能找到版本LATEST的依赖。 此回答表示我如何使用leiningen在本地引用此项目。

I have two leiningen projects. According to this question, maven should allow me to use "LATEST" as a dependency version. It is giving me an error suggesting that the dependency with version "LATEST" can't be found. This answer represents how I'm referencing this project locally with leiningen, if that matters.

如何让这个工作?如果这不是您在项目中引用本地依赖项,我可以接受其他建议。

How do I get this to work? If this isn't how you reference local dependencies in your project, I'm open to alternative suggestions.

项目文件如下所示:

(defproject mongo-model "0.0.19-SNAPSHOT"
            :description "A simple way to create model templates for mongodb for write-time data validation"
            :dependencies [[org.clojure/clojure "1.3.0"]]
            :main mongo-model.core)

(defproject bayou "0.1.0-SNAPSHOT"
            :description "FIXME: write this!"
            :dependencies [[org.clojure/clojure "1.3.0"]
                           [mongo-model "LATEST"]]
            :main bayou.server)

运行 lein deps 第二个项目给我这个错误:

Running lein deps in the second project gives me this error:

An error has occurred while processing the Maven artifact tasks.
 Diagnosis:

Unable to resolve artifact: Missing:
----------
1) mongo-model:mongo-model:jar:LATEST

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=mongo-model -DartifactId=mongo-model -Dversion=LATEST -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=mongo-model -DartifactId=mongo-model -Dversion=LATEST -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) org.apache.maven:super-pom:jar:2.0
    2) mongo-model:mongo-model:jar:LATEST

----------
1 required artifact is missing.

for artifact: 
  org.apache.maven:super-pom:jar:2.0

from the specified remote repositories:
  clojars (http://clojars.org/repo/),
  central (http://repo1.maven.org/maven2)



Exception in thread "main" Unable to resolve artifact: Missing:
----------
1) mongo-model:mongo-model:jar:LATEST

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=mongo-model -DartifactId=mongo-model -Dversion=LATEST -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=mongo-model -DartifactId=mongo-model -Dversion=LATEST -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) org.apache.maven:super-pom:jar:2.0
    2) mongo-model:mongo-model:jar:LATEST

----------
1 required artifact is missing.

for artifact: 
  org.apache.maven:super-pom:jar:2.0

from the specified remote repositories:
  clojars (http://clojars.org/repo/),
  central (http://repo1.maven.org/maven2)

 (NO_SOURCE_FILE:0)
    at clojure.lang.Compiler.eval(Compiler.java:5440)
    at clojure.lang.Compiler.eval(Compiler.java:5391)
    at clojure.core$eval.invoke(core.clj:2382)
    at clojure.main$eval_opt.invoke(main.clj:235)
    at clojure.main$initialize.invoke(main.clj:254)
    at clojure.main$script_opt.invoke(main.clj:270)
    at clojure.main$main.doInvoke(main.clj:354)
    at clojure.lang.RestFn.invoke(RestFn.java:457)
    at clojure.lang.Var.invoke(Var.java:377)
    at clojure.lang.AFn.applyToHelper(AFn.java:172)
    at clojure.lang.Var.applyTo(Var.java:482)
    at clojure.main.main(main.java:37)
Caused by: Unable to resolve artifact: Missing:
----------
1) mongo-model:mongo-model:jar:LATEST

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=mongo-model -DartifactId=mongo-model -Dversion=LATEST -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=mongo-model -DartifactId=mongo-model -Dversion=LATEST -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) org.apache.maven:super-pom:jar:2.0
    2) mongo-model:mongo-model:jar:LATEST

----------
1 required artifact is missing.

for artifact: 
  org.apache.maven:super-pom:jar:2.0

from the specified remote repositories:
  clojars (http://clojars.org/repo/),
  central (http://repo1.maven.org/maven2)


    at org.apache.maven.artifact.ant.DependenciesTask.doExecute(DependenciesTask.java:175)
    at org.apache.maven.artifact.ant.AbstractArtifactTask.execute(AbstractArtifactTask.java:678)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:90)
    at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:265)
    at leiningen.deps$do_deps.invoke(deps.clj:131)
    at leiningen.deps$deps.doInvoke(deps.clj:195)
    at clojure.lang.RestFn.invoke(RestFn.java:410)
    at clojure.lang.Var.invoke(Var.java:365)
    at clojure.lang.AFn.applyToHelper(AFn.java:161)
    at clojure.lang.Var.applyTo(Var.java:482)
    at clojure.core$apply.invoke(core.clj:542)
    at leiningen.core$apply_task.invoke(core.clj:228)
    at leiningen.core$_main.doInvoke(core.clj:294)
    at clojure.lang.RestFn.invoke(RestFn.java:410)
    at clojure.lang.AFn.applyToHelper(AFn.java:161)
    at clojure.lang.RestFn.applyTo(RestFn.java:132)
    at clojure.core$apply.invoke(core.clj:542)
    at leiningen.core$_main.invoke(core.clj:297)
    at user$eval42.invoke(NO_SOURCE_FILE:1)
    at clojure.lang.Compiler.eval(Compiler.java:5424)
    ... 11 more
Caused by: org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
----------
1) mongo-model:mongo-model:jar:LATEST

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=mongo-model -DartifactId=mongo-model -Dversion=LATEST -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=mongo-model -DartifactId=mongo-model -Dversion=LATEST -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) org.apache.maven:super-pom:jar:2.0
    2) mongo-model:mongo-model:jar:LATEST

----------
1 required artifact is missing.

for artifact: 
  org.apache.maven:super-pom:jar:2.0

from the specified remote repositories:
  clojars (http://clojars.org/repo/),
  central (http://repo1.maven.org/maven2)


    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:324)
    at org.apache.maven.artifact.ant.DependenciesTask.doExecute(DependenciesTask.java:170)
    ... 34 more


推荐答案

这里有两件事:标准依赖解析和方便 checkouts 目录

There are two things at play here: The standard dependency resolution and the convenience of the the checkouts directory.

checkouts 目录的功能非常简单:Leiningen希望找到一个或多个目录, Leiningen项目。通常你在这里为你的其他项目创建符号链接。对于每个链接的项目,将source-path,compile-path和resources-path添加到类路径。 (默认情况下,可以配置目录列表。)

The functionality of the checkouts directory is pretty simple: Leiningen expects to find one or more directories there, each containing another Leiningen project. Usually you create symlinks to your other projects here. For each of the linked projects, the source-path, compile-path and resources-path are added to the classpath. (By default - the list of directories can be configured.)

这意味着链接项目的命名空间在父项目中可用,无论是否包括在依赖或不。

This means that the namespaces of the linked projects are available in the parent project, no matter if they are included in the dependencies or not. You should still include them in the dependencies though, so other people can work with your codebase.

依赖关系解析机制不关心 checkouts 目录。它试图找到本地和远程Maven存储库中的所有依赖项。如果你对一个从未安装在仓库中的本地项目有依赖性,那么它就不能被找到,Leiningen将会出现一个错误,如你的问题所示,即使该项目链接在 checkouts 目录。

The dependency resolution mechanism doesn't care about the checkouts directory. It tries to find all dependencies in the local and remote Maven repositories. If you have a dependency on a local project which you never installed in a repository, then it cannot be found, and Leiningen will bail out with an error like the one shown in your question, even if the project is linked in the checkouts directory.

您需要至少在本地存储库中安装一次所需的工件。这就像调用 lein install 一样简单。你不需要在每次更改后都这样做,因为你总是通过 checkouts 符号链接使用最新的代码。

You need to install the artifacts you are depending on at least once in your local repository. This is as easy as calling lein install. You don't need to do this after every change, since you're always using the latest code via the checkouts symlink.

关于使用 LATEST :我会说鼓励使用固定版本号的依赖。这是防止一次成功构建因为依赖性的改变而突然中断的唯一方法。另请参阅此问题:如何我要告诉Maven使用最新版本的依赖吗?

Regarding the use of LATEST: I would say it is encouraged to use fixed version numbers for the dependencies. This is the only way to prevent that a once successful build will suddenly break because of changes in the dependencies. See also this question: How do I tell Maven to use the latest version of a dependency?

这篇关于使用maven的“LATEST”关键字在leiningen项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆