How to create a mixed Scala and Java Maven Project? - java

I have googled aplenty, and I find scraps of info here and there, most old, and I haven't found a good answer.
I need to write scala and Java, and I'd like to do so inside the same maven project. I would like to use IntelliJ or Netbeans if that matters, with the latest Scala lib and Java 8.
What is the best way to create a maven project with Scala and Java code in it?
I've seen this but it's kind of old
Maven: mixing Java and Scala in one project

Related

Can a Maven solution have polyglot projects? (Java, Python, Scala)

Is it possible to have in the same solution a project in Java, another in Python and another in Scala? Or all the projects must be either in Java either in Scala?
You can mix Java and Scala in a single Maven project. Read the following tutorial for more information:
Scala with Maven
Python and Maven: well python doesn't need to be compiled like Java or Scala code does. Instead, python project building is about resolving dependencies, running unit tests, creating installables and so on. Unfortunately, python has its own way of doing these things that different from Maven. To the extent that it probably doesn't make much sense for Maven to manage python code.
Having said that, you can "lightly integrate" python into a Maven build system by having Maven run a setup.py script as an external command. Here is an article that describes this approach:
Python & Java: a unified build process (1/4)

Interop Clojure from java

I'm doing a java project with some friends of mine, using intellij as IDE and gradle to build the project, recently I started learning clojure and I'd like to include Clojure code in our java project, as we know if it was Lein handling the project I coud easely interop both java and clojure with each other, but my friends have no interest in using Clojure or changing the project structure (understandably of course), is there anyway I can keep the development using gradle and intellij without having to compile Clojure into jar and include it has a external dependency? (use gradle so it can build the java and clojure in the same project or something like that)
I already tried finding plugins but I couldnt get it to build the project from intellij has it would keep getting errors... Thanks in advance for the responses.

Alternatives to Maven for Java and Scala Development

I've been using Maven for a while for my Java (and now Scala) projects. Recently, I've seen some talk about issue with Maven (example). Personally, I'm happy with it till now. I've used sbt for Scala a little bit and I think it works well.
Again my point here is not to say which system is better but to expore out what other alternatives exist and how real developers are using them for Java and Scala projects.
There is a Scala plugin for Gradle.
Alternatively you could use Scala's built-in Ant tasks and Ivy for dependency management (which is what SBT uses internally).
Yet another option is Apache Buildr.
Pretty much any build system designed for Java-based projects should work with Scala.
Related:
A Basic Ant+Ivy+Scala Setup
Comparing SBT and Gradle
Buildr vs. Gradle
I think if you're going to use Scala, you'll need to become familiar with SBT. It's the standard build system for Scala projects, and the build system of choice at every professional organization that I have worked at using Scala.
SBT has a bit of a learning curve, but it also has some amazing features - console is probably the one I use most - load up a shell with your project already on the CLASSPATH.
You can do some pretty clever stuff with SBT - in the end it's all Scala under the hood. The effort to pick it up is well worth it if you plan to work with Scala professionally.

Introducing scala into existing netbeans java project

I have an existing java project in Netbeans. I would like to start coding parts of it in Scala. I can add ".scala" files to the project but apparently they aren't compiled.
Can I somehow modify the existing Netbeans project settings in order to build java and scala sources together or do I need to create a new project and import the existing (java) sources?
Thanks
Martin
EDIT Sorry, I forgot to mention: I've installed the Scala-Plugin for netbeans, so compiling scala code is feasible.
I can create a new (Scala) project and add both scala and java sources to it and it compiles perfectly. My question was if (and how) it's possible to migrate an existing "java-only" project towards such a "mixed" project.
I don't think this is possible in the way you want it. You could however write an Ant build-script and let Netbeans execute it when building you application.
Otherwise I suggest to just create a new scala project and import it as *.jar library into your Java application. This keeps your project clean and nicely modularized.
You will need to migrate to use something like Maven to do this for you, as Netbeans doesn't know how to compile Scala code. Maven can be configured to compile the .scala files first then the .java, resulting in your final compiled source.
Have a look here for the maven config.
I would recommend doing a new maven project, Project form Archetype, and use the following.
http://mvnrepository.com/artifact/org.scala-tools.archetypes/scala-archetype-simple/1.3
This basically auto imports you a project all set up to get started running scala in a Java project.

How do you setup a maven java project that can also make use of groovy?

I'm working on a large existing java project using maven to manage our builds / releases.
I'm interested in using groovy to replace some of our Java classes where we can benefit from it's dynamic nature.
How do I go about doing this using maven?
Have you tried the gmaven plugin?
This is listed on the Groovy Wiki, also have a look at GMaven.

Categories

Resources