Adding and removing dependencies with SBT and Scala IDE - eclipse

I've been experimenting with SBT and the Scala IDE (Eclipse) and I'm wondering - what's the standard workflow for adding and removing dependencies from your build.sbt file where the project's referenced libraries will be updated in Eclipse?
Are there any current plugins that are required to use sbt with eclipse when adding / removing dependencies?

The sbteclipse plugin will do it. The key is that whenever you change your dependencies you need to re-run the command to create the Eclipse files. I use:
eclipse same-targets
Then you need to right-click on the project in Eclipse and choose Refresh.

I also needed this. I can confirm that re-running the eclipse task from the sbteclipse plugin (version 1.3-RC3 for SBT 0.10.1) will indeed regenerate the Eclipse project files (these are .project and .classpath). If you're seeing something else, it sounds like a bug that should be reported.

Related

Running Gradle inside Eclipse?

There appears to be an Eclipse plugin for Gradle, but no Gradle plugin for Eclipse...
Simply, I'd like to add a build.gradle to my Eclipse project, write its contents (including defining its dependencies), and then run it from inside Eclipse, the same way I can run Ant scripts from inside Eclipse.
When it runs, I'd expect the plugin to pull down all dependencies and make them available to my project's classpath in Eclipse.
If no such plugin exists, then I ask: what's the best way to develop in Eclipse, but keep your builds managed by Gradle? If I decide I need a new xyz.jar as a dependency for my code, how do I add it as a dependency in such a way that both Gradle and Eclipse will recognize it (and not throw compiler errors)?
Either use the IDE project generation approach (gradle eclipse), or use the Eclipse Gradle Integration. In both cases, you'll want to apply plugin: "eclipse".
The Gradle plugin for Eclipse is part of the Spring IDE. It understands the dependencies specified in the build script and makes those available in the .classpath.

setting up a maven project in Juno Eclipse

I recently upgraded my Eclipse to Juno and am struggling with the way maven dependencies are handled.
I installed the m2e plugin. Still, many of my projects started complaining about libraries missing as if the dependencies specified in the pom were completely ignored. This happened despite right-clicking on the project, selecting Configure --> Convert to Maven project, which seems to be the replacement for what used to be "Maven --> Enable dependencies" before. When I looked at the Maven dependencies under the project directory, there were many fewer dependencies listed than in my pom.
Running a maven compile on the command line outside of Eclipse allowed my project to build and after selecting Maven --> Update project, I was able to see the dependencies added or removed accordingly to what I specified in the pom.xml.
Bottom line: maven dependencies seem to work now but I had to do some combination of operations I didn't think should have been needed:
- Configure -> Convert to Maven project
- Maven -> Update dependencies
- Run maven outside of Eclipse
To get everything to work when with previous versions of Eclipse, all I had to do was Maven -> enable dependencies. What is the equivalent of this in Juno, i.e. what is the correct way of setting up juno Eclipse to handle properly a maven project?
I have been using Juno for a while now and the reliable way to solve Maven dependencies from within Eclipse after importing a project that is maven based is simply:
Configure --> Convert to Maven project
Maven --> Update project
Running Maven outside of Eclipse doesn't seem to help.
I am not sure why these two steps are now required when they were not before with previous version of Eclipse (at least, two steps were not needed before for sure).
Running
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
outside of Eclipse has brought me the problems I described in my comment to the other answer.
On a Mac running Windows under Parallels Desktop on OS X? This similar discussion may solve your problem: intellij - java: Cannot find JDK '1.7' for module

How eclipse maven and ant work together?

I made simple maven project and I opened it with Eclipse. I have installed maven plugin for Eclipse. I'm interested in following:
How Eclipse compiles code when I hit save on my source code (does it use configuration from ant or maven or something else)?
When I run tests from JUnit plugin for Eclipse those Eclipse calls mvn test (I suppose not, but what is then happening exactly)?
Is it possible that maven does the build successfully but Eclipse is
showing errors in code?
The Maven Integration for Eclipse makes it easier to edit POM files, allows you to execute maven builds from within Eclipse and to help with dependency management. It doesn't actually compile your code (unless of course you execute a maven build from within Eclipse). The main help is with the dependency management and writing the .classpath file of your project within Eclipse.
To try and answer your questions:
Eclipse uses its standard mechanism to compile code. With a standard eclipse for java developers your project will have a Java Project nature and Eclipse will then use the Java Development Tools - JDT to compile the code. (Internally this uses an incremental builder to build the code http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_builders.htm). What source files it will compile and where it will place the resultant .class files is configured in your project's Java Build Path (which I am guessing the maven plugin may well configure for you)
JUnit support is part of the Java Development Tools as well.
It is possible that maven will successfully build a project outside of Eclipse, but that the same project will show errors within Eclipse. This is usually down to classpath errors (dependencies defined in the project's POM not being added to the classpath in Eclipse). If you are using the maven plugin with eclipse this probably shouldn't happen. If you are not using the maven plugin within eclipse you can execute maven eclipse:eclipse to have maven update the Eclipse .classpath file of the project which should then fix any of these problems.

Working with a Scalatra application in an Eclipse workspace? (i.e. build path)

I am experimenting with a small Scalatra web application, which I have imported as a project into Eclipse.
I have used Eclipse to manage a few Lift applications before. With a Lift project, SBT copies all the dependency JAR's to a /lib_managed directory. I can therefore add those JAR's to Eclipse's build path, and it co-exists with SBT just fine without complaining about missing classes.
With Scalatra, however, the dependency JAR's don't seem to get copied anywhere helpful during the development cycle. If you build a WAR file, then the dependencies get bundled up into that... but there doesn't seem to be anything like Lift's /lib-managed directory.
Assuming that anyone else uses Eclipse in developing Scalatra projects, how might I easily set up Eclipse's build path? I suppose that I could manually create entries that point my local Ivy repository one-by-one, although that seems a bit ugly. Perhaps there's an easy way through SBT to setup something similar to Lift's /lib-managed subdirectory inside the project directory.
It looks like the best approach for this is using the SBT plugin for Eclipse.
This is not an "Eclipse plugin" for managing SBT. Rather, it's an "SBT plugin", for generating the .project and .classpath files used by Eclipse. The Maven world used to deal with Eclipse in a similar manner, before the m2eclipse Eclipse plugin reached maturity over the past couple years.
With this plugin installed (I installed it globally so I wouldn't have to change my project's files), you just type sbt eclipse after any changes to your dependencies. SBT will then update your Eclipse project files to match.
You could also use my Maven prototype, then simply import the maven project into Eclipse. Quite nice and you're not forced to use SBT.
https://github.com/fancellu/scalatra-maven-prototype

maven adds dependency but eclipse does not see it

I've created a new project in maven like this:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
After that I use: mvn eclipse:eclipse
The problem is that when I add the project to my IDE, eclipse indicates errors. When I run it I get classNotFound for JUnit. In project properties I see that junit is added to build path
In project properties I see: M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar
But I cant use for example: import junit.framework.Test;
Why is that? To be honest, I have some major problems with dependency in maven and eclipse. Maven adds them correctly but eclipse doesn't see it correctly. It's not only the junit. What should I check/set?
Should I install some plugin to eclipse for maven support ?
EDIT
I thought again about everything. Of course the problem was small. M2_REPO was not recognize by Eclipse. I've added this variable and set it in od maven directory. It worked like a charm.
You can use the m2eclipse plugin for eclipse
http://m2eclipse.sonatype.org/installing-m2eclipse.html
I don't know if having the plugin would solve your problem, I used to do the command line before I started using m2elcipse, I never had the issue that you described
what version of eclipse are you using?