Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading Scala version in a Maven project in IDEA

I am using IDEA 10.5.2 with Scala plugin version 0.4.1395 and the standard Maven integration plugin that ships with the IDE. I have a Scala 2.8.0 project with the above setting, and I want to upgrade it to Scala 2.9.1. I made the necessary changes to pom.xml. Here are the relevant sections from my pom.xml:

Plugin section:

  <plugin>
    <groupId>org.scala-tools</groupId>
    <artifactId>maven-scala-plugin</artifactId>
    <executions>
      <execution>
        <id>compile</id>
        <goals>
          <goal>compile</goal>
        </goals>
        <phase>compile</phase>
      </execution>
      <execution>
        <id>test-compile</id>
        <goals>
          <goal>testCompile</goal>
        </goals>
        <phase>test-compile</phase>
      </execution>
      <execution>
        <phase>process-resources</phase>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
    </executions>
  </plugin> 

Dependencies section:

<dependency>
  <groupId>org.scala-lang</groupId>
  <artifactId>scala-compiler</artifactId>
  <version>2.9.1</version>
</dependency>
<dependency>
  <groupId>org.scala-lang</groupId>
  <artifactId>scala-library</artifactId>
  <version>2.9.1</version>
</dependency>

I have Scala 2.9.1 installed on my machine.

In my project settings, in the Scala facet, the compiler instantiation section has several options for "compiler library". However my project doesn't build on selecting any of them.

When I select Maven: org.scala-lang:scala-compiler-bundle:2.9.1, I get the following error:

Cannot compile Scala files.
Please, adjust compiler library in Scala facet: unable to read scala-library-2.9.1.jar version.

When I select Maven: org.scala-lang:scala-compiler:2.9.1, I get the following error:

Cannot compile Scala files.
Please, adjust compiler library in Scala facet: no scala-library*.jar found.

When I select Maven: org.scala-lang:scala-library:2.9.1, I get the following error:

Cannot compile Scala files.
Please, adjust compiler library in Scala facet: no scala-compiler*.jar found.

What am I doing wrong? What should I do to get my project build?

Please note that I am using a build tool for the first time. Any help would be greatly appreciated. Thanks!

like image 700
sanjay Avatar asked Sep 19 '11 14:09

sanjay


1 Answers

If you are working with a maven project in IDEA changing the Scala version is usually very easy.

First you have to make sure that IDEA is using your maven project configuration. You can check this by right-clicking on the pom.xml. If you see a menu entry "Add as maven project" (or something similar) click on it. Otherwise you should see a sub menu called "Maven" which means that your maven project is already configured properly.

Now you can change the Scala version in your pom.xml and IDEA should immediately download the corresponding packages and change the Scala compiler in project settings (if you have auto-import of pom files enabled). Otherwise IDEA pop up a message allowing you to perform the pom file import manually.

However, I did not test this workflow with the Scala plugin 0.4.1395, because I had some troubles with this plugin version. I finally went back to version 0.4.1385 which is IMO very stable. If you have any troubles with your Scala plugin I suggest you the same.

like image 75
Stefan Endrullis Avatar answered Nov 15 '22 04:11

Stefan Endrullis