Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross build scala using gradle

Tags:

gradle

scala

I've got a Scala project that is built with Gradle. The Scala code is source compatible with scala 2.9 and 2.10 and I'd like to cross build it to both major Scala versions. Does Gradle support this?

For example, my gradle project will have a single module:

    build.gradle
    src/main/scala/foo.scala

and I'd like the resulting published jars to be:

    org-foo_2.9-0.1.jar (with dependency on scala-library 2.9)
    org-foo_2.10-0.1.jar (with dependency on scala-library 2.10)
like image 649
Joe Avatar asked Jan 30 '14 07:01

Joe


2 Answers

Gradle's Scala plugin doesn't currently support cross-building. It's possible to implement it yourself, though. In my Polyglot Gradle talk, I presented a proof-of-concept.

like image 157
Peter Niederwieser Avatar answered Oct 23 '22 13:10

Peter Niederwieser


I am searching for a good example of this. The Gradle manual doesn't mention how to specify Scala version but looking at the source code for the Scala plugin it seems to infer it from the Scala library jar that you specify.

The best example I could find is the Apache Kafka build system. It specifies the Scala version and then uses some additional logic to resolve the correct version of the Scala libraries. It also uses some logic to attach the correct label to the jars its builds to correspond to the correct Scala version.

This feels like a lot of work and something that the build system should do for you like in SBT.

like image 20
Mark Butler Avatar answered Oct 23 '22 13:10

Mark Butler