installationclojureenvironment-variablessnapshotleiningen

Why do I need to prefix `lein install` with `LEIN_SNAPSHOTS_IN_RELEASE=true` for the installation to succeed? What are the reasons behind this?


If I run lein install the terminal throws an error:

➜  lein install

If there are a lot of uncached dependencies this might take a while ...
Release versions may not depend upon snapshots.
Freeze snapshots to dated versions or set the LEIN_SNAPSHOTS_IN_RELEASE environment variable to override.

But, if I do what the (obscure) error message suggests and if I prefix the command with LEIN_SNAPSHOTS_IN_RELEASE=true, it succeeds:

➜  LEIN_SNAPSHOTS_IN_RELEASE=true lein install

If there are a lot of uncached dependencies this might take a while ...
Created /Users/pedro/projects/my-project-name/target/1.3.0-ONE-PROJECT-REPOSITORY-NAME.jar
Wrote /Users/pedro/projects/my-project-name/pom.xml
Installed jar and pom into local repo.

I would like to understand this better.

Why is the prefix needed? Why can't Lein just accept lein install? What is the reason/context behind this design?

Obs.: on project.clj the project name does not include the word SNAPSHOT. I have:

(defproject my-project-name "1.3.0-ONE-PROJECT-REPOSITORY-NAME" ...

Solution

  • I suspect one of your dependencies are pointing to a SNAPSHOT version?

    I guess Leiningen does not allow you to release a "stable" (non-SNAPSHOT) version of anything that depends on something non-stable itself. Imagine your library depending on function xyz in the library [abc "1.0.0-SNAPSHOT"]. But in the snapshot version of abc released tomorrow the function xyz have been refactored, so the function signature is different, or maybe xyz has been removed altogether. Now your stable library doesn't work anymore.

    That is why Leining wants it to be a deliberate decision (that takes extra effort) to do such things. But without knowing the exact version of Leiningen and the full dependency tree, I cannot say for sure, nor reproduce the behavior locally.

    Also see the Leiningen documentation:

    Snapshot Versions

    Sometimes versions will end in "-SNAPSHOT". This means that it is not an official release but a development build. Relying on snapshot dependencies is discouraged but is sometimes necessary if you need bug fixes, etc. that have not made their way into a release yet. However, snapshot versions are not guaranteed to stick around, so it's important that non-development releases never depend upon snapshot versions that you don't control. Adding a snapshot dependency to your project will cause Leiningen to actively go seek out the latest version of the dependency daily (whereas normal release versions are cached in the local repository) so if you have a lot of snapshots it will slow things down.

    Note that some libraries make their group-id and artifact-id correspond with the namespace they provide inside the jar, but this is just a convention. There is no guarantee they will match up at all, so consult the library's documentation before writing your :require and :import clauses.