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). Each developer would have to set up their own maven repo, distinct from the project.
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.
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. (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. So, the task has simplified from previous versions.
Create a directory inside your project called, in this example, myrepo. (The name is arbitrary)
Add a :repositories entry in your project.clj file with a path to the local directory you created.
:repositories [["localrepo1" "file:myrepo"]]
Deploy your free floating jar to the repo.
lein deploy localrepo1 com.blueant/fancypants 1.0.1 fancypants.jar
And, add your dependency to your project.clj :dependencies vector as normal.
: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. You can verify your jar is loaded correctly with the lein deps :tree command.
Note: File paths in :repositories are formatted as URLs. So, /Users/user1/Desktop is file:///Users/user1/Desktop, and, a local directory within the project, myrepo is file:myrepo.
I'd like to elaborate on #Jared314's excellent answer that helped me as well.
Below is a script that automates the process of adding multiple jars from a local lib folder to a local repository:
#!/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.
Before running the script, :repositories entry in project.clj has to be updated to allow for reading repository username and password from the environment:
: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. If you have many dependencies changing versions creating a repo is the recommended approach.
Related
I am trying to create an atlassian's bamboo plugin in clojure. The jar must contains a file called atlassian-plugin.xml at top level. How can I do so with leiningen. I expect to create my jar using lein jar.
cheers!
didier
You could put atlassian-plugin.xml in src (not sub folder) or resource folder. It will be on the top level same as project.clj.
I'm trying to deploy a (non-snapshot) library to Clojars using Leiningen. I've actually been able to deploy this library before but it was a while ago and now I've made some fixes that I want to release. I even have a small bash script that used to handle the release and deploy process that essentially just do:
RELEASE_VERSION=${releaseVersion} lein release
Where releaseVersion is supplied as a parameter to the script. I'm using the lein-release plugin and I've specified:
:lein-release {:deploy-via :clojars}
in my project.clj. I also have working (or at least they used to work) GPG credentials in /Users/johan/.lein/credentials.clj.gpg.
When running lein release I'm prompted for my GPG password but after a couple of seconds I run into this:
$ RELEASE_VERSION=0.2.1 lein release
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
[master cf4e5d1] Version 0.2.1
1 file changed, 1 insertion(+), 1 deletion(-)
You need a passphrase to unlock the secret key for
user: "Johan <email>"
2048-bit RSA key, ID ABC123431, created 2015-11-12
No credentials found for releases (did you mean `lein deploy clojars`?)
Password prompts are not supported when ran after other (potentially)
interactive tasks.
See `lein help deploy` for an explanation of how to specify credentials.
I've also tried setting repositories in my project.clj:
:repositories [["releases" {:url "http://clojars.org/repo" :creds :gpg}]]
But it doesn't make any difference. Does anyone know how to solve this?
The problem was that I had accidentally removed [lein-release "1.0.9"] from {:user {:plugins .. }} in my ~/.lein/profiles.clj file. When I added it again everything worked as expected.
We are hosting a corporate repository which acts as a proxy to the well-known repositories (e.g. Maven Central and Clojars). I want Leiningen to hit the corporate repository in the first place. Only when the corporate repository fails to deliver the artifact Leiningen should ask the standard repositories. This should be the default behaviour of all my projects. What configuration I have to do?
I have added the corporate repository as a mirror in ~/.lein/profiles.clj:
{:user {:mirrors {"our-repo" {:name "our-repo"
:url "http://our-repo/all/"}}}}
Unfortunately this setting has no impact. Leiningen downloads the artifacts from Maven Central:
PS> lein repl
Retrieving org/clojure/clojure/1.5.1/clojure-1.5.1.pom from central
...
Update
xsc suggests to overwrite the Maven Central repository with a mirror definition which points to the corporate repository. It works. Now instead of going to the external Maven Repository Leiningen retrieves the artifacts from the corporate repository.
S/He also suggests to specify an additional repository definition to install a fallback mechanism.
Unfortunately this does not work so well because Leiningen complains about this setting:
:repositories detected in user-level profiles! [:user]
See https://github.com/technomancy/leiningen/wiki/Repeatability
This warning is very annoying. For this reason I would abstain from this setting. Is there another way to install a fallback mechanism?
Here's what works for me:
{:user {:mirrors {#".+" {:url "http://nexus.example.com:8081/nexus/content/groups/public"}}
:repositories [["snapshots" {:id "NudaySnapshots"
:url "http://nexus.example.com:8081/nexus/content/repositories/snapshots"}]
["releases" {:id "NudayReleases"
:url "http://nexus.example.com:8081/nexus/content/repositories/releases"
:sign-releases false}]]}
:auth {:repository-auth {#"nexus.example.com" {:username "deployment"
:password "foo bar baz"}}}}
This handles both resolving dependencies through my Nexus mirror and publishing artifacts to it with lein deploy.
I get the annoying "Repeatability" warning, but I'm working on getting rid of that.
As far as I can see in Leiningen's example project.clj you have to use the name of the repository to mirror as the key in the :mirrors map. So, try this:
{:mirrors {"central" { ... }}}
This will most likely replace the repository completely, so you might want to add the original again:
{:mirrors {"central" {:url "..." }}
:repositories {"maven" {:url "http://repo1.maven.org/maven2/"}}}
I use a local library to do some development, but the firewall prevents alot of internet sites. Is there a way to download artifacts manually?
My project.clj is:
https://github.com/zubairq/coils/blob/master/project.clj?
Update
From the comments given I am understanding that the steps to take are:
1) Install Maven
2) Find out which jars are in my project (How can I do this based on my project.clj?)
Dependency Tree
In order to figure out which jars your project needs you can do:
$ lein deps :tree
Which will show you something that is called a "dependency tree". It will look similar to:
[clj-time "0.5.0"]
[joda-time "2.2"]
[clojure-complete "0.2.3"]
[org.myproject/some-proto "0.0.1-20130523.145830-9"]
[org.flatland/protobuf "0.7.2"]
[ordered-collections "0.4.0"]
[org.flatland/schematic "0.1.0"]
[org.flatland/useful "0.9.0"]
[com.datomic/datomic-free "0.8.3862"]
...
Installing Jars with Lein
One simple way to install manually downloaded jars would be to use "lein-localrepo":
$ lein localrepo install [-r repo-path]
[-p pom-file]
<filename>
<[groupId/]artifactId>
<version>
Here are a couple of examples (given that you have downloaded the jars):
$ lein localrepo install foo-1.0.6.jar com.example/foo 1.0.6
$ lein localrepo install foomatic-1.3.9.jar foomatic 1.3.9
Take a look at the documentation for more features and examples.
Installing lein-localrepo
You can install lein-localrepo as a plugin by adding the following to your ~/.lein/profiles.clj:
{:user {:plugins [[lein-localrepo "0.5.2"]]}}
Lein Behind a Proxy Server
In case it is "ok" to use a proxy server, you can add it to ~/.lein/profiles.clj under jvm-opts
{:user {:jvm-opts ["-Dhttp.proxyHost=168.1.1.104" "-Dhttp.proxyPort=8080"]}}
where user is a profile name to use.
Or you can export http_proxy environment variable before launching lein.
As per instructions at Jclouds website, I downloaded the Lein BAT file, and also downloaded Curl to the same folder. I am working on a Windows 8 x64 PC.
Now I created a file named "project.clj" within the folder containing lein and curl.
After that, I ran the following command--
lein deps
However, all this does is create a file within following path (within the folder containing Lein and curl)--
target\scale\dependencies
The file named "dependencies" contains the following text--
([:dependencies [[org.jclouds/jclouds-all "1.5.3"] [org.jclouds.driver/jclouds-sshj "1.5.3"]]])
I am not sure what I am doing wrong here... How do I download all of the jclouds files correctly?
sorry, this was updated with lein 2. jclouds.apache.org doc is now corrected.
After creating project.clj...
Execute lein pom, then mvn dependency:copy-dependencies which will fill target/dependency with all the jclouds jars.