What's the best way to manage dependencies with CounterClockwise/Eclipse? - eclipse

I have a dependency on clj-record in my CounterClockwise project. What's the best way to manage this? Copy the source code or compile to a JAR and add it as a referenced library?

There are tools to help you:
http://github.com/technomancy/leiningen <- project based
http://github.com/liebke/cljr <- dependencies not project based
http://github.com/ninjudd/cake <- alternative build tool

Assuming your dependencies are available in a Maven repo (like central or clojars), you have a couple of options.
First, if you're using Leiningen, there is an eclipse plugin for it now that will manage project dependencies for you, based on the dependencies you define in your project.clj file. The plugin is in beta now, but has been working great for me so far. (Note that it uses Leiningen 2.0 under the covers, though that detail won't matter for many (most?) simple cases.)
If you're using Maven, the m2eclipse plugin makes it so that the dependencies you declare in your Maven pom.xml are automatically added to your eclipse project's build path, and are therefore available in CCW REPLs and such.

there seems to be no pattern for specifying dependencies apart from hacking the code into your project or building a jar externally.
Of course you can, just as with any java project. While dependency resolution isn't tied into eclipse (yet), once you retrieve the deps (via one of the command line tools nickik listed), you can specify which jars are to be included in the java build path of your eclipse project:
Retrieve the deps via cake, leiningen, etc.
Refresh the eclipse project so you see the deps (usually in the lib directory)
Highlight the jars you want eclipse to know about
Right-click, select Build Path > Add to Build Path
That's it. You can fiddle with the build path by going to the Java Build Path section of the project's properties window.

Related

The best practice to use Tycho/Maven to remove jars dependencies in Eclipse RCP?

I'm working one an Eclipse RCP project. Currently we create a dependencies plug-in project and put all jars libraries into that project and export all packages. This method will give a huge repo, thus we want to use Tycho/Maven and let it figure out the dependencies for us.
The first approach is removing dependenciec project and use p2-maven-pluging to transform existing jars libraries to p2 format repo. Install all libraries from p2 repos and add required bundle in Require-Bundle section in each MANIFEST.MF. This is a little bit tedious since in every project having dependencies in Require-Bundle, I have to manually replace it to corresponding bundle names. And in the end, the project build using Tycho could successfully run, but in Eclipse it gives me java.lan.NoClassDefFoundError: Could not initialize class X.
I think there are few configuration files, where Tycho depends on some of them and Eclipse depends on the rest, but I'm not sure what it is.
The second approach is removing all jars in dependencies project but adding them in Require-Bundle or Import-Package. However, both won't work since in Export-Package section Eclipse will complain these packages are not existed. Thus other projects depends on this dependencies project won't find those packages they need, which causing more errors in Eclipse.
Does anyone know the best practice to deal with this issue?
Update:
I'm using basically the first approach, but add dependencies in Import-Package in each project instead of Require-Bundle. This would eliminate the need to specify the specific bundle version, as long as they provide the same API and they are compatible, your application would work. So everytimes I update private p2 repository, I don't need to change MANIFEST.MF in each project.
The only MANIFEST.MF I need to manually add dependencies in Require-Bundle is a library developed by our self. Without it, Tycho won't fetch required dependencies from private p2 repository. If still get NoClassDefFoundError, try adding all plugins in Run -> Run Configuration .. -> plug-ins, it may help.
I definitely not apply your approach 1, with the mega-plugin of exports. There's a related discussion here: Handling non-OSGi dependencies when integrating Maven, Tycho and Eclipse
As a rule, use Import-Package instead of Require-Bundle.
To get bundles will appear in the Export-Package section Eclipse:
if they are non-Eclipse (maven libraries), then build the project and reference the libraries in the Eclipse runtime section.
if they are Eclipse dependences, they should be in your workspace or Target Platform.
More generally, it may help for you to define a Target Platform. You can build/deploy all of your locally created plugins into a local p2 repository (see http://www.sonatype.org/nexus/). Then add that p2 site to your Target Platform.

scala sbt cache x eclipse build path

I'm added a dependence to my build.sbt (casbah). I did a sbt update, I did check my ~/.ivy2/cache directory and all jars are there. Do I have to add this ~/.ivy/cache directory to my Build Path and add the casbah as external Jar to my project? If no, probably no because I did try it, what should I do to be able to use this jar in my scala project?
EDIT
I found this instructions that helped me, but still a hack
Establish a simple project (general/project) named "IvyCache"
located at your ".ivy2/cache" folder just for library reference
purposes.
Establish a Scala project located at your "project" folder.
Add the following libraries to the Scala project by means of "Add
JARs" to the "Java Build Path":
3.a) All jars from "/IvyCashe/org.scala-tools.sbt" filterred by
"*2.9.1-0.11.2" or any other Scala/SBT version numbers.
3.b) A single sbinary_*.jar from "/IvyCache/org.scala-tools.sbinary".
3.c) A single test-interface*.jar from "/IvyCache/org.scala-
tools.testing".
Now your build files should compile within Eclipse.
The easiest way to manage this is to use the eclipse plugin for sbt. Then you can just say sbt eclipse on the command line any time you change the dependencies in build.sbt, and the Eclipse files will be automatically updated for you.
Doing it this way means that you will never have to manually configure your Eclipse build path. After all, sbt already knows how to construct the build path, so there's no reason you would have to do it manually.

cmake, add_subdirectory without adding it to the generated project file?

I have a project that is build with cmake. In my cmakelists I have a
add_subdirectory(externals/foo)
to build the dependency "foo" which has it's own cmakelists.
Now it is so that also the whole foo sources and headers are included in the generated Project file (I'm using Eclipse). But all I want is to only have my project available in Eclipse (Eclipse has problems with subprojects in the same folder structure).
So that the cmakelists from "foo" is only used to build "foo" automatically and link it to my project. I don't want to see it in my IDE however.
Is this possible? If yes: How?
When I use Eclipse with CMake, I create the Eclipse project manually (with the New Project wizard) and for CMake I use the standard makefile generator. It requires a little extra setup: you need to set the build directory in the project properties if you're doing an out-of-source build, and I usually set the build command to make VERBOSE=1.
I'm not sure since I haven't used the Eclipse generator(s), but for the lack of a better solution, perhaps this method would solve your issue, since it gives you more control over the Eclipse project.
No, how should the ide know what to compile if you don't tell it what to compile? If you don't want to have the project in you project file, just don't add it.
Just compile the external lib by itself (use "cmake externals/foo") and then add the libraries in your project's CMakeLists.txt with
target_link_libraries(your_project externals/foo/bin/foo.lib)

Grails Project - Common Java Project Dependency in Eclipse

All,
We have standard java projects that contain our common data model, common util classes, etc...
What I can’t seem to figure out is how, to make my Grails project (in Eclipse) have a dependency on the other standard (non Grails) java project in the workspace. When I add the project in the “Java Build Path” the project doesn’t show any compiler errors, but it when I run “Grails Tools -> Refresh Dependencies” or attempt to run the project (run-app) it fails.
This seems like it would be a pretty common thing, but I have searched all over the web and have been unable to find a solution. We are not using maven in our environment. Since we build Eclipse RCP applications on the client side, we use OSGI manifests to manage our project / bundle dependencies.
You can use linked source directories to include the Java or Groovy dependencies in the grails project and you need to set the output directory to Project/target/classes (these configurations go into the grails project preferences in Java Build Path options -> Source Tab).
The change in the output directory allows Eclipse to detect changes in the dependencies and auto load it when running the app using grails run-app.
You can use autocomplete and debug the sources of the dependencies with this configuration.
I prepared a step and step process that includes screenshots for Java and Groovy here
The documentation includes information on customizing the build.
You can add this to your BuildConfig.groovy:
grails.compiler.dependencies = {
fileset (dir:"/path/to/jars")
}
That should get you started.
If the dependencies are not stored in an Ivy/Maven repository then AFAIK your only option is to copy the dependencies to the lib directory of the Grails project.

Extract eclipse project .classpath dependencies into ant script

I have a list of Eclipse projects that I would like to compile based on the existing project configuration.
As far as I can tell, if an ant script could read the .classpath files, it would pretty much be able to infer the project dependencies and perform a "javac" compilation in the right order. This would save time in describing the same dependencies again in the ant script or a Makefile.
The dependencies I am interested in are JAR Dependencies, JRE dependencies, and inter-project dependencies. These are -- as far as I can tell -- part of the .classpath XML file.
Any ideas on how Eclipse project dependencies could used in an ant script?
Right click on your Project -> Export
"General/Ant Buildfiles".
Choose the projects and there you go.
Otherwise...
I have some experience with ant4eclipse and it is a hassle to get it stable.
Go check Buckminster or Maven Tycho for a good solution.
I'm currently using Ivy along with Ant, Eclipse and Maven.
I just love the way Ivy works.
Currently, we have a workspace with many projects using Liferay (with Tomcat) for the front-end and Glassfish for the back-end.
We were looking for a way to manage our dependencies a lot better than how we were doing it.
So I took Ivy, replaced all of the classpaths and deployment dependencies in eclipse and was able to build my application using 1 ivy file per project using either Eclipse or Ant.
Ivy integrates like a charm in ant and builds are done either from the workspace or by command line.
I strongly suggest you look at this avenue. Additionnaly, by adding Artifactory, we have a local repository in which the ivy files look for dependencies. This helps us maintain and rule which jars are to be used by developpers. Once everything is setup, we will build our application nightly using Jenkins and these builds will be using our Artifactory repository to resolve dependencies since our build servers do not have access to the internet.
Hope this helped
If you are running the Ant script only from eclipse using the "External Tools Configurations", you can add the variable ${project_classpath} to the Classpath.
Depending on if you are in a plugin project and dependencies you might need to add the
${eclipse_home}.
In case you get an error launching Variable references empty selection: ${project_classpath}, make sure the ant xml file or at least the project is selected. This is important.
I believe the ant4eclipse project provides support for executing Ant builds based on Eclipse metadata files.
However, in my opinion that is doing things back to front. You shouldn't have your build (Ant) depending on your IDE (Eclipse) environment. But it is useful if you can derive your Eclipse environment from your Ant build.
This is an approach used successfully in a team I worked in. We had a helper Ant target which applied XLST to project build.xml files to transform these into Eclipse .classpath files. Thus the Ant build.xml files were the single configuration point for our projects.