Is there any way to avoid Scala libraries appearing twice in an Eclipse/Scala/Maven project? - eclipse

I have
Eclipse 3.5.2
Scala 2.8.0 final (inc latest Scala IDE for Eclipse)
Maven integration for Eclipse
Maven 2.2.1
.project and .classpath files generated by maven-eclipse-plugin
I'm using Scala to write Specs BDD tests for my Java code and the setup above is working very nicely so far. However, I have one puzzling problem and I would like to know whether anyone knows how to resolve it.
The Scala libraries are appearing in my project twice.
in the M2 ClassPath (as a Maven Dependency)
as an Eclipse System Library (in the same manner as the JRE System Libraries)
Consequently, when I Ctrl-Shft-T every Scala class appears twice.
Can this be avoided without breaking my Scala project in either the command line or the Workspace?

The best place for questions like this is the Scala IDE user mailing list.
The most up to date documentation on using the Scala tooling for Eclipse with Maven via m2eclipse can be found here.

To answer my own question,
it appears (as hinted at by all above) that maven-eclipse-plugin is essentially obsolete. When I
deleted my old eclipse project
removed all eclipse files (ie .settings and .project from my project directory)
removed all references to maven-eclipse-plugin from my pom
installed the m2eclipse-scala plugin
re-imported the project as a maven project
all settings were detected correctly and I no longer saw the double entry of scala classes in my classpath.

Related

Tycho projects without Java code have Java nature in Eclipse

I have imported my Tycho project in Eclipse using m2eclipse and I have the following issue: Tycho adds the Java nature to eclipse-plugin projects that don't have any Java code, for example the help plugin. It's not a big deal, but I find it annoying.
Is there any way to disable this?
Tycho doesn't define a separate packaging type for Eclipse plug-ins without code.
So if the Tycho Project Configurator, i.e. the m2eclipse extension for Tycho, wanted to omit the Java nature for eclipse-plugin projects, it could only do so after scanning the entire project for *.java files. And even then it would not be clear if the project does not contain Java code, or simply not yet contain Java code.
So, having the Java nature on all eclipse-plugin projects is a simple and robust choice that makes sense IMHO.

Creating a new Maven Scala project in Eclipse results in 4 errors

Edit 2: I seem to have discovered the problem: the JAR files that were downloaded to my m2 repository are corrupt:
It seems to me that they could be causing the problems. But why are they corrupt? And how can I fix that?
Edit: I've ran mvn eclipse:clean eclipse:eclipse in the project, and it completed successfully... and introduced 5 additional errors:
On another PC I've created a Scala Maven project using the m2eclipse and Scala IDE plugins for Eclipse. I don't remember any errors. Then I pushed it to GitHub.
I then proceeded to clone the project on my laptop, but I was first greeted with this (error) message:
After selecting yes, what seemed to be the logical step, these errors appeared:
What's going on and how can I fix it?
(Linux, Elementary OS)
It is possibly a difference in Scala versions used. Scala IDE is usually based on specific version of Scala. Looks like your project pom.xml requires different version of Scala.
A solution is to either update your pom.xml to version of your IDE or upgrade the Scala IDE if possible.
The other possibility is that downloaded jars are corrupted.

What is a "build manager" for scala in the scala ide extensions for Eclipse?

In Eclipse in Preferences -> Scala -> Compiler -> Build manager, I can select a "buildmanager." What is the difference between "refined" and "sbt"?
Also, is this some method to integrate an sbt build file into the Eclipse IDE?
ScalaIDE has two build managers, basically they are interfaces between the eclipse model and the scala compiler, they have to do things like work out which resources need re-compiling and how that affects dependent code. Refined is a refined version of the original interface and sbt is, well, sbt.
SBT is the default now, and I expect refined will go away at some point.
Unfortunately the build manager is very much under the hood. There is no real eclipse project->sbt integration yet. There is an eclipse plugin for sbt which allows you to generate eclipse project files but no tight integration from an eclipse project to sbt akin to IvyDE or m2e.
You can use sbt deliver-local to create an ivy file of dependencies, and use IvyDE to keep your classpath containers up to date - that's about as good as it gets at the moment.
I wouldn't be surprised to see this situation improve though - check out the roadmap.

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

Importing a Scala project from github into Eclipse

I've installed EGit plugin in my Eclipse Helios with latest Scala IDE plugin beta. I've imported it as a "general project" using clone and I can't find any Configure -> Add Scala nature option ... what am I doing wrong? (can't compile/run/add libraries etc)
I'm not familiar with the EGit Plug-in, but do you also have the option to import it as a Java project? The "Add Scala Nature" option is only available for Java projects.
If you can't create it as a Java project, you can also just modify the generated .project file and add the Java nature to it manually:
<nature>org.eclipse.jdt.core.javanature</nature>
(taken from http://enarion.net/programming/eclipse-change-general-to-java-project/)
One recommended approach would be first to make your GitHub project compiled/run with sbt (which ensures both IDE-independence and third-party library dependency management).
The sbt-eclifsify can easily generates .classpath and .project files for the Eclipse IDE from the sbt project.
The class ProjectFile.scala details how the .project file is build.