I know there are Scala specific tools to create OSGi bundles, but I'm quite happy with bndtools, I just would like to write Scala alongside or instead of Java.
Asked
Active
Viewed 331 times
1 Answers
3
Assuming that bndtools and Scala IDE installed in eclipse (you find them the Eclipse Marketplace).
- Create a new Bndtools OSGi project as you normally would (i.e. from the
File
menu, selectNew
->Bndtools OSGi Project
) - Add the Scala nature to the project: Right click on the project in the Package Explorer view, and in the context menu select
Configure
→Add Scala Nature
. (See http://scala-ide.org/docs/user/faq.html)
That's all for the eclipse side of things, you can now add Scala classes and everything will work the same way as it does with java.
To make sure things also work on the command line and on your CI Server some more steps are needed.
- to the file
build.gradle
add the line:apply plugin: 'scala'
- to file
gradle.properties
add:scara.srcDirs=[projectDir/src]
UPDATE:
The above isn't quite enough, additional a build.bnd file has to be added to any submodule containing scala files. The following isn't elegant as it duplicates a dependency already in the bnd file, but so far the only solution I've found: https://github.com/fusepoolP3/p3-entry-resource/blob/0df0bc35311c8a361f95d8e72f91c5e0df929245/build.gradle

Reto Gmür
- 2,497
- 1
- 20
- 25
-
@evandor: I've changed the link to point to old revision with the file – Reto Gmür Nov 23 '16 at 17:41
-
For debugging purposes - when using your scala jar as a dependency in another project - you might want to add this to your bnd file as well: -includeresource: OSGI-OPT/src=src/ This will add the scala sources to your bundle which would otherwise be ignored. – evandor May 11 '17 at 17:26