Scala and java interation in Eclipse - eclipse

I have a Eclipse project (Xtext) and want to use Scala code in the project.
The Scala code also need to use a Scala library which uses sbt.
That will be the best way to perform this integration in Eclipse?

Related

Scala Plugin in Intellij

I am using Scala plugin in IntelliJ. If I want to use Scala in command line, do I have to install regular scala in my machine or is there anyway I can use the Scala plugin installed in IntelliJ outside of IntelliJ?
Thanks,
You have to install Scala separately to be able to use it on the command line. IDEA uses Scala via SBT, but this is not a Scala you could use from a command line. The alternative to using REPL from the IDE could be to use Scala scratch file functionality.

XML Library Missing in Scala Eclipse Distribution

I need to use Scala's XML processing capabilities, but the XML library has been removed from Scala 2.11.x. On Scala's website, it shows instructions on how to get the library using SBT. I don't use SBT -- I use their Eclipse editor (the Scala IDE). How / where do I get the XML libraries when using the Scala IDE?
You can download required version from Scala site. In extracted archive find
scala/scala-2.11.4/lib/scala-xml_2.11-1.0.2.jar
Just add this jar to your Eclipse project Build Path.

Is it possible to use gradle to develop scala projects?

I'm using sbt to build scala projects, but it always seems too complex(unfamiliar) and heavy to me. I'm also using gradle to build java projects, and which makes me happy.
I wonder is it possible to use gradle to build scala projects? Is there any big scala projects that uses gradle?
Some of my friends just tell me "Never ever think of using gradle for scala project", but refused to tell me the reason.
It's quite easy to use Gradle with Scala.
We did it for a long time (a mixed team of Java, Groovy and Scala developers) and have been quite happy with it.
Most things work quite well out of the box.
More about Gradle with Scala:
http://www.gradle.org/docs/current/userguide/scala_plugin.html
There are some problems/downfalls though:
Mixed code compilation when depending on Scala code from Java in mixed code projects. (Some configuration and it will work, but not out of the box)
More configuration for Scala-specific tools needed than with sbt
Integration of some Scala tools like Scalastyle or scct is not possible yet
no sbt console (Gradle console has not been working properly since the last time I checked)
adding the Scala version number to artifacts has to be added manually each time (no %% as in sbt)
It's definitely possible. Gradle's Scala support is documented in the "Scala plugin" chapter in the Gradle User Guide. The plugin is used by big companies on big projects, and can be configured to use the same incremental Scala compiler as sbt. So best try for yourself and see if it fits your requirements.

Eclipse Scala IDE: How to build standalone Scala app?

I am writing an app that uses AnormCypher (Cypher-oriented Scala library for Neo4j Server https://github.com/AnormCypher). I write my code in Eclipse Scala IDE. Using sbteclipse plugin I have imported AnormCypher sbt project into Eclipse. Next I have added it to Java build pass as external project. Everything compiles and works from Eclipse now.
Question: How in Eclipse build a standalone Scala program with all necessary dependencies including external Scala project imported in Eclipse?
Trying to create'executable jar' from Eclipse does not work in this case because to do so Eclipse requests "Select a 'Java Application' launch configuration to use to create a runnable JAR." Alas Eclipse here has no idea about Scala launch configuration.
There is not currently a feature of the Scala IDE.
However, it's easy to write a simple build file for your project using sbt. Once there, you can use one of the numerous available plugins to create a distribution for it. Sbt has its own sbt-assembly and sbt-oneJar to create standalone JARs, and there is twitter's sbt-package-dist, with more varied publishing options.

When creating a maven module project, how to set language to scala?

I have intellij 11 ultimate.
When creating a new maven module project, how do I set the project to use scala as the default language?
Is there a way to run multiple versions of scala in intellij? (not at the same time, but for different projects).
I think you can create a normal java project and then go to project structure -> modules-> facets and add the scala facet if you have the scala plugin installed.
The version of scala your project will use depends on the scala runtime selected in the facet, so yes it's possible to have different scala versions in different projects.
When importing a Maven project into IntelliJ, as long as you have installed the Scala plugin for IntelliJ, I think it should recognise the project as Scala and add the Scala Facet to the Module.
Here is an example https://github.com/adamretter/Skullfuck/blob/master/pom.xml of a simple Maven POM that I use that includes the better of the two Maven Scala Plugins. If you also install Zinc, you can have Maven use the Zinc compiler to speed up Scala compilation.
If IntelliJ does not recognise the Scala'ness of the imported Maven project, simply go to 'Module Settings' by right-clicking on the project, go to 'Facets' and then click the '+' and add the Scala facet. If it complains about not finding the compiler you should be able to select it from the down as it is a dependency of the Maven project anyway.