[英]How do I use checked-in jars with leiningen
We have some 3rd-party jars checked-in to our project. 我们在我们的项目中签了一些第三方罐子。 We'd like to add them to the classpath.
我们想将它们添加到类路径中。 That's it.
而已。 We don't want to set up a local maven repo (because that would break our 'check out and run' philosophy).
我们不想建立一个本地的maven回购(因为这会破坏我们的'检查和运行'理念)。 Each developer would have to set up their own maven repo, distinct from the project.
每个开发人员都必须设置自己的maven仓库,与项目不同。
Is there a way to do this or is this? 有办法做到这一点还是这样? Most of the answers I've seen say to set up a local maven which we don't want or need just to add a jar to a classpath.
我见过的大多数答案都说要设置一个我们不想要或只需要在类路径中添加jar的本地maven。
You will need to setup a local maven repository, but that can be a simple directory, in your project directory, that you then check in to source control. 您需要设置一个本地maven存储库,但这可以是项目目录中的一个简单目录,然后您可以检入源控件。 (Which will maintain your 'check out and run' policy)
(这将保持您的“签出和运行”政策)
As of Leiningen 2.2.0 the functionality to deploy jars is built-in with the lein deploy
task. 从Leiningen 2.2.0开始,部署jar的功能内置了
lein deploy
任务。 So, the task has simplified from previous versions. 因此,该任务已从先前版本简化。
Create a directory inside your project called, in this example, myrepo
. 在项目中创建一个名为
myrepo
。 (The name is arbitrary) (这个名字是任意的)
Add a :repositories
entry in your project.clj
file with a path to the local directory you created. 在
project.clj
文件中添加:repositories
条目,其中包含您创建的本地目录的路径。
:repositories [["localrepo1" "file:myrepo"]]
Deploy your free floating jar to the repo. 将自由浮动的jar部署到repo。
lein deploy localrepo1 com.blueant/fancypants 1.0.1 fancypants.jar
And, add your dependency to your project.clj :dependencies
vector as normal. 并且,将您的依赖项添加到project.clj
:dependencies
向量正常。
:dependencies [[com.blueant/fancypants "1.0.1"]]
The deploy task will generate the checksums and directory structure required to to tie into the lein dependency resolution. 部署任务将生成与lein依赖关系解析相关联的校验和和目录结构。 You can verify your jar is loaded correctly with the
lein deps :tree
command. 您可以使用
lein deps :tree
命令验证jar是否已正确加载。
Note: File paths in :repositories
are formatted as URLs. 注意:
:repositories
中的文件路径格式为URL。 So, /Users/user1/Desktop
is file:///Users/user1/Desktop
, and, a local directory within the project, myrepo
is file:myrepo
. 因此,
/Users/user1/Desktop
是file:///Users/user1/Desktop
,以及项目中的本地目录, myrepo
是file:myrepo
。
I'd like to elaborate on @Jared314's excellent answer that helped me as well. 我想详细说明@Jared314的优秀答案对我有帮助。
Below is a script that automates the process of adding multiple jars from a local lib
folder to a local repository: 下面是一个脚本,它自动将多个jar从本地
lib
文件夹添加到本地存储库的过程:
#!/bin/sh
export LOCALREPO_USERNAME=
export LOCALREPO_PASSWORD=
for file in lib/*.jar
do
name=$(basename "$file")
basename=${name%.jar}
echo "Deploying $basename"
artifactId="local/$basename"
lein deploy localrepo1 $artifactId 1.0 $file
echo "[$artifactId \"1.0\"]" >> dependencies.log
done
The list of Leiningen dependencies that can be added to project.clj
is stored in dependencies.log
. 可以添加到
project.clj
的Leiningen依赖项列表存储在dependencies.log
。
Before running the script, :repositories
entry in project.clj
has to be updated to allow for reading repository username and password from the environment: 在运行脚本之前,必须更新
project.clj
:repositories
条目,以允许从环境中读取存储库用户名和密码:
:repositories [["localrepo1" {:url "file:myrepo"
:username :env/localrepo_username
:password :env/localrepo_password}]]
This will prevent the repository password prompt from displaying when running the script. 这将阻止在运行脚本时显示存储库密码提示。
This question has already been answered here . 这个问题已在这里得到解答。
It is indeed possible, but there's a reason why maven
and dependency management exists. 这确实是可能的,但是存在
maven
和依赖管理存在的原因。 If you have many dependencies changing versions creating a repo is the recommended approach. 如果您有许多依赖项,那么更改版本会创建一个repo,这是推荐的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.