Gradle Scala plugin - How to specify scala version - scala

How can I specify the Scala version in a Gradle Scala project?
The official documentation states that the scala-library dependency is used to get hold of the compiler.
dependencies {
compile 'org.scala-lang:scala-library:2.11.1'
}
Does this mean that Scala 2.11.1 will be used?

Specify the Scala library in the dependencies like so:
dependencies {
compile 'org.scala-lang:scala-library:2.11.1'
}

Related

Scala-reflect not found

I have a Kotlin based Gradle project, where I'm using Scala. All my dependencies are coming from the internal repository, so I cannot use any Scala version, but only the ones available.
Because of that I have the following list of dependencies:
plugins {
java
}
//...
apply(plugin = "scala")
//...
dependencies {
implementation("org.scala-lang.scala-reflect:2.12.5")
compileOnly("org.scala-lang.scala-library:2.12.9") {
exclude("org.scala-lang.scala-reflect")
}
On paper it should work - I defined dependencies available on internal nexus.
However, when I try to build the project, I'm getting the following error:
Execution failed for task ':compileScala'.
> Could not resolve all files for configuration ':zinc'.
> Could not find scala-reflect-2.12.10.jar (org.scala-lang.scala-reflect:2.10.10).
> Searched in the following locations:
<nexus_url>
Is it because of scala plugin?
UPDATE
I have checked that the error occurs, because the version of Zinc I have is built on top of Scala 2.12.10. And since the version is not available on the nexus, it cannot be ran.
Is there a way to change the Scala version Zinc is using?
After searching through Gradle Scala plugin documentation (https://docs.gradle.org/current/userguide/scala_plugin.html#sec:configure_zinc_compiler)
I have found the solution.
What I had to do was changing the Zinc version:
scala {
zincVersion.set("1.3.1")
}

Problem building scala 2.13.1 with Gradle 6.2 (worked with 5.6.2)

I want to use Gradle 6.2 because of the recently fixed scaladoc issue.
Here is a build scan of my Gradle build using version 5.6.2 and Scala 2.13.1 - which works fine.
Without changing the Gradle build file at all, other than changing the version to 6.2, I now get this error:
> Could not resolve all dependencies for configuration ':zinc'.
> Conflict(s) found for the following module(s):
- org.scala-lang:scala-library between versions 2.12.8, 2.12.2, 2.12.1 and 2.12.0
- com.google.protobuf:protobuf-java between versions 3.7.0 and 3.3.1
- org.scala-lang.modules:scala-xml_2.12 between versions 1.0.6 and 1.0.5
I studied the suggested dependency graph but don't know how I am supposed to resolve the conflicts. I don't know why it is trying to use scala 2.12 at all.
Here is the corresponding build scan for this failing build.
I see that dependency configurations like "compile" are now deprecated. I tried changing to the newer preferred configurations, but I'm not certain that I mapped them all correctly.
I tried this:
dependencies {
implementation "java3d:vecmath:$vecmathVersion"
testImplementation 'junit:junit:4.12'
compileOnly("org.scala-lang:scala-library") {
version {
require "2.13.1"
}
}
testImplementation 'org.scalatest:scalatest_2.13:3.1.1'
testRuntimeOnly 'org.pegdown:pegdown:1.6.0'
}
but get the same error as above.
Please see this post for a bit more detail about how gradle works with Scala dependencies.
I suggest simplifying your dependencies section first, and using a specific version of scala, to get it working. I don't see why you you only want the scala-library at compile time and not runtime? The Gradle Scala plugin requires it to be a generally compile-time dependency: https://docs.gradle.org/current/userguide/scala_plugin.html.
The same documentation says that Gradle uses 2.12 to compile 2.13 sources... so I suspect that the 2.12 dependency is creeping in because you did not explicitly declare your scala-library version.
Without knowing the value of $vecmathVersion, I suggest the following:
dependencies {
implementation group: 'java3d', name: 'vecmath', version: '1.3.1'
implementation group: 'org.scala-lang', name: 'scala-library', version: '2.13.1'
testImplementation 'junit:junit:4.12'
testImplementation 'org.scalatest', name: 'scalatest_2.13', version: '3.1.1'
testImplementation 'org.pegdown:pegdown:1.6.0'
}

.jar files cross-compiled with an incompatible version of Scala (2.10)

I am building my first Scala/Play application and after I create and import an eclipse project from the Play shell, I get 17 errors.
akka-actor_2.10.jar is cross compiled with an incompatible version of Scala (2.10)
akka-slf4j_2.10.jar is cross compiled with an incompatible version of Scala (2.10)
anorm_2.10.jar ...
play_2.10.jar ...
play_iterates_2.10.jar ...
The list goes on to include the Scala jars, scalaz jars, etc...
I am using:
Eclipse 4.2.2
Scala ide 3.0.0.nightly-2_09
Scala 2.10
Play 2.1
Has someone experienced the same thing?
Is it possible you are using Scala IDE built for for Scala 2.9.x ?
Make sure you use the one for 2.10.x:
http://download.scala-ide.org/sdk/e38/scala210/dev/site/

Running scalatest and Maven with two scala libraries - one for Maven, the other for Scala Eclipse plugin

The scala Eclipse plugin requires scala 2.10.0 to run :
To run the 'test' goal on Maven I require the dependency :
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.0-1</artifactId>
<version>2.0.M5</version>
</dependency>
As part of this dependency 'scala-library-2.9.0-1.jar' is also added to build path :
This causes an error to be displayed on problems tab in Eclipse :
More than one scala library found in the build path. At least one has
an incompatible version. Please update the project build path so it
contains only compatible scala libraries.
How can I fix this error ? I need both scala libraries, one is for the scala eclipse plugin and the other for the scalatest maven plugin. I don't want to just delete the error from the problems tab.
The scala Eclipse plugin requires scala 2.10.0 to run :
It has versions for both 2.10 and 2.9, install the one for 2.9.2 (and use ScalaTest for version 2.9.2 as well). Or use a version of ScalaTest for 2.10, but it seems you'll need to build and install it locally, there isn't one for 2.10.0-RC2 listed at http://mvnrepository.com/artifact/org.scalatest.

How do i change the Scala version that sbt works with?

Firing up the SBT console it reads :
[info] Building project AYLIEN 1.0 against Scala 2.8.1
[info] using MyProject with sbt 0.7.4 and Scala 2.7.7
How can I make it use MyProject with sbt 0.7.4 and Scala 2.8.1 ? Please pay attenetion that I'm not asking about the Scala version that is used to build my project (it is the 2.8.1 as you can see), but I rather want to make sbt use MyProject with Scala 2.8.1. Apparently sbt uses it's own scala version to work with project definition (MyProject here) which is different than one it uses to actually build the project! or perhaps I'm missing something ... ?
I can see your concern about SBT still using 2.7.7 internally, but it doesn't really matter since SBT downloads that version on its own. You do not have to install 2.7.7 or anything, just forget about it and pretend your environment is pure Scala 2.8.
The configuration file that holds the SBT version setting is: project/build.properties. The content looks like this:
project.organization=com.ab.web
project.name=cool_proj
sbt.version=0.7.4
project.version=1.0
build.scala.versions=2.8.0
project.initialize=false
When you want to move up to the next SBT version, just change 0.7.4 to that version and SBT will update itself. Eventually SBT will use some other Scala version internally, but this will not matter to the user.
SBT 0.7.* won't work with Scala 2.8.* for your project definition.
Mark Harrah is currently working on the next version of SBT which will work with 2.8.*. This means that you can't use any Scala features or functionality that was added after Scala 2.7.7 in your project definition or plugins. Your project itself is free to use 2.8.*.