How to use leiningen to develop using local jars? - maven

I realize that this question is pretty much the exact question found here. However, seeing as that question is 1.5 years old (or so), I would like to revisit it. How does one add local dependencies using leiningen? Surely this capability must exist by now?

Create a private Maven Repository, and then, add the following to your project.clj
:repositories {"local" ~(str (.toURI (java.io.File. "your_local_repository")))}

If the jars are based on your own projects, you can use lein install to put them into your local .m2, or use the checkout-dependencies feature.
You can also use the extra-classpaths feature, etc.

I found that the easiest (albeit somewhat hacky) solution is to do the following:
For an existing project that you're using as a dependency:
In your local project that has the dependency you want to modify, ensure you run lein deps
Clone the repo of this dependency so you can modify it locally (obv. make sure you're using the same tag as the version you specify in your project.clj file)
Run lein uberjar in this dependency dir (where the relevant project.clj file lives)
Copy the generated standalone jar in target/ to the exact path/file of your local maven files... (something like: ~/.m2/repository/project/.../file.jar); Ensure that you backup the original jar file so you can restore it later on if that is desirable
For development of your own project:
Within the project or plugin you're developing, simply run lein install
Find out where your local maven repo is (see above for an example path)
Enter dependency information in your test project like you would for any other leiningen project
Again, this is a quick hack and perhaps not the way you'd go about doing serious local development, but I found it easy enough for what I wanted. Check out lein help tutorial for much more info

Related

How to download dependencies using Bazel?

I am new to Bazel. I need to download external dependency jar files using Bazel. Where to configure to download external jar files. I tried to add jar files in BUILD and WORKSPACE files , but not working.
Workspace file
maven_server(name="myserver",url="https://mvnrepository.com/artifact/org.apache.flink/flink-java")
maven_jar(name="flink-java",artifact="org.apache.flink:filnk-java:jar:1.2.0",server="myserver")
bind(name="flink-java",actual="#flink-java//jar")
Build file
java_binary(
name="read_files",
srcs = glob(["ReadFiles.java"]),
main_class="com.ibm.cdo.gts.contracts.pipeline.preprocess.ReadFiles",
deps=["//external:flink-java"],
)
The logical mistake you have there is that the workspace name (flink-java) is illegal see here and here. What is needed is to change the - to _ in maven_jar and of course the reference in the bind.
maven_jar(name="flink_java",artifact="org.apache.flink:flink-java:jar:1.2.0")
bind(name="flink-java",actual="#flink_java//jar")
Two more mistakes you had in the above were:
In the artifact coordinates you wrote filnk-java when you needed flink-java
The mvnrepository URL you used doesn't seem to be legal. I tried a few variants but couldn't get it to work. Additionally from the site they seem to link downloads to Maven Central itself so I'm not sure they server the jars. Having said that since Bazel fallbacks to Maven Central I just omitted the maven_server and the build passes. If you need help with the maven_server part and you need to use a private Maven repository please double check the URL first.
PS: It would have really helped if you added to your question the Bazel outputs since I needed to create my own workspace to know what were the problems you encountered.

What's the recommended way of building ELKI's current development status?

I forked ELKI from https://github.com/elki-project because I want to keep up to date with the latest development status while making my own changes and additions to the source (which I will possibly provide via pull request if it's sensible).
I followed the instructions in the README.md to package it with mvn package but there was no .jar created in elki/target/ - when checking out the release0.7.1 branch, it worked and I could start the minigui with java -cp elki-0.7.1.jar de.lmu.ifi.dbs.elki.application.ELKILauncher.
Is there a recommended way to try out the latest changes on the master?
We are currently in the process of modularizing ELKI.
But mvn package does create .jar files in elki/target/ here:
elki/target/elki-0.7.2-SNAPSHOT.jar
elki/target/elki-0.7.2-SNAPSHOT-javadoc.jar
elki/target/elki-0.7.2-SNAPSHOT-sources.jar
elki/target/dependency/elki-core-dbids-0.7.2-SNAPSHOT.jar
elki/target/dependency/elki-core-dbids-int-0.7.2-SNAPSHOT.jar
elki/target/dependency/elki-core-util-0.7.2-SNAPSHOT.jar
elki/target/dependency/elki-docutil-0.7.2-SNAPSHOT.jar
elki/target/dependency/elki-logging-0.7.2-SNAPSHOT.jar
elki/target/dependency/hamcrest-core-1.3.jar
elki/target/dependency/javaparser-core-2.3.0.jar
elki/target/dependency/junit-4.12.jar
elki/target/dependency/trove4j-3.0.3.jar
The main jar, ./elki/target/elki-0.7.2-SNAPSHOT.jar is runnable, but will only include the command line interface because of modularization - the minigui is optional now.
If you want a all-in-one bundle (as distributed on the web site), you need to enable the Maven profile bundle in addition to the functionality you want to include (e.g. mvn -Psvg,svm,uncertain,bundle package).

how to force maven to update local repo

I compiled a jar file in one project so it can be consumed in the 2nd one. I can see the jar file in .m2 folder. But in the 2nd project it complains about artifact not found.
I guess I have to force maven to update indices/cache something but don't know what exactly. Any tip, thanks.
Update: thanks for all good suggestions.
Turns out that the maven plugin (of IntelliJ) in the second project doesn't update its index. I use command line it compiled ok.
try using -U (aka --update-snapshots) when you run maven
And make sure the dependency definition is correct
You can also use this command on the command line:
mvn dependency:purge-local-repository clean install
If you are installing into local repository, there is no special index/cache update needed.
Make sure that:
You have installed the first artifact in your local repository properly. Simply copying the file to .m2 may not work as expected. Make sure you install it by mvn install
The dependency in 2nd project is setup correctly. Check on any typo in groupId/artifactId/version, or unmatched artifact type/classifier.
Even though this is an old question, I 've stumbled upon this issue multiple times and until now never figured out how to fix it. The update maven indices is a term coined by IntelliJ, and if it still doesn't work after you've compiled the first project, chances are that you are using 2 different maven installations.
Press CTRL+Shift+A to open up the Actions menu. Type Maven and go to Maven Settings. Check the Home Directory to use the same maven as you use via the command line
Click settings and search for "Repositories", then select the local repo and click "Update". That's all. This action meets my need.
If you are struggling with authenticating to a site, and Maven is caching the results, simply removing the meta-data about the site from the meta-data stash will force Maven to revisit the site.
gvim <local-git-repository>/commons-codec/resolver-status.properties

how to prevent gradle from downloading dependencies

We would like to have a script that does "svn update" and if the depedency.gradle file is in that list of updates, we would like to run a task that ONLY updates dependencies so the developers machine is up to date. What would that task be? I don't see it when running "gradle tasks". Looking for an updatejars or something.
When we build our project, we don't want it to check for jar updates at all!!!! most because that only needs to be done in 2 situations which are #1 above and when someone is updating the dependency.gradle file themselves. For the second thing, they can just run "gradle updatejars" once I know the answer to question #1 that is.
Any ideas? I am just getting into gradle and we really want to keep a consistent environment where when we run our update script, it gets the source code AND the jars in one atomic sweep and we are no longer bothered by checking the repositories every build.
It would be nice to know how to do it by changing the build.gradle file if possible. If not, is there a command line option? (The build.gradle obviously would give me a command line option which is why I prefer that method as I could say compile does not depend on downloading jars).
Regarding the second question. As far as I understand, Gradle will not attempt to do remote lookups or try to download the jar if it is already in the local cache. This should be true for jars declared with a static version, e.g. testCompile 'junit:junit:4.10'.
If you have dynamic versions, e.g. 1.+ or 1.0-SNAPSHOT, etc. then Gradle has to do a check every now and then. You can fine tune the cache expiry for such dependencies.
To make sure Gradle does not do remote lookups you can also use --offline option. See this doc for details.
With regard to svn update, you have at least 3 options:
Try to use an SvnKit plugin for Gradle
Use the ant svn task (here's how to do svn checkout)
Run external command from Gradle. Use the ExecPlugin or just implement it yourself using Groovy API.
Looks like the 1st question I can do with the answer in this post
how to tell gradle to download all the source jars
so I can just gradle eclipse and it will download new jars and update my classpath...nice.

How to index a Maven repo without Nexus/Artifactory/etc?

I run my own little Maven repo for some open source. I have no dedicated server so I use a Google code repository, deploy to file system and then commit and push. Works perfect for me.
But some Maven tools are looking for a nexus-maven-repository-index.properties and the index (in GZ). I would like to generate this index to
get rid of the warning that it's not here
Maven doesn't try the repo for artefacts that are not there.
How can I do that? Is there a tool (Java main) that is able to generate an index? Also tips how to use the proper Nexus Jars with a little commandline tool are welcome.
I came across this post while I was searching for a solution to add a local repository to my Maven project using IntelliJ Idea.
Since Sonatype changed their paths and reorganized the downloads since the last post, here is an updated step-by-step tutorial to get your repository indexed for use with IntelliJ Idea:
Download the latest stand-alone indexer from here.
Extract it somewhere and go into this directory
From the console, run this command: export REPODIR=/path/to/your/local/repo/ && java org.sonatype.nexus.index.cli.NexusIndexerCli -r $REPODIR -i $REPODIR/.index -d $REPODIR/.index -n localrepo
In the directory .index within the repository directory, some files will be created including the file "nexus-maven-repository-index.gz" which is the file IntelliJ looks out for.
You can use the Maven Indexer CLI to product the index directly, but why bother hosting your own repo when OSS projects can use a hosted one for free?
http://nexus.sonatype.org/oss-repository-hosting.html
I was looking at maven indexer... but I am not sure what for is the last parameter indexDir in the method:
public RepositoryIndexer createRepositoryIndexer(String repositoryId,
File repositoryBasedir,
File indexDir)
is it like starting point in the repositoryBasedir?

Resources