Introducing	Scala	in	your
existing	Java	project
Tim	Soethout	-	ING	Bank
http://blog.timmybankers.nl
Overview
Intro
Scala	@	ING	-	Context
Compiling	Scala	in	Maven
Mixing	Java	and	Scala	source
Code	coverage
Code	quality	using	Sonar
More	code	analysis
Documentation	for	Java	consumers
Wrap	up
Who	am	I?
Tim	Soethout
Functional	programmer	at	heart
Scala	evangelist/trainer	inside	ING
More	recently:	Aquarium	enthusiast	&	West	Coast	Swing-
dancer
Scala	@	ING
State
Much	Java	with	Maven
Some	Scala	for	restful	services	using	Akka
Open	source:	Coral
Developers	are	getting	interested	and	looking	for
possibilities
Context
Maven	project	written	in	Java	6
Team	with	mixed	Scala	experience	levels
Eager	to	do	Scala
But	within	Enterprise:	Compliancy
Compiling	Scala	in	Maven
scala-maven-plugin
<project>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
...
</plugin>
</plugins>
</build>
</project>
Mixing	Java	and	Scala
source
Demo
Mixed	Java	&	Scala
Demo
Multiple	modules
Mixing	it	up
Seems	to	work	on	first	sight
Problems	can	arise	in:
Multiple	modules
Dependencies	from	Java	to	Scala
Depends	on	compile	order
sbt	incremental	compiler	to	the	rescue
scala-maven-plugin:
<configuration>
<recompileMode>incremental</recompileMode>
</configuration>
Another	option;	runs	sbt	underneath
Not	really	maintained	anymore,	but	helped	us	a	lot	6
months	ago
sbt-compiler-maven-plugin
<plugin>
<groupId>com.google.code.sbt-compiler-maven-plugin</groupId>
<artifactId>sbt-compiler-maven-plugin</artifactId>
<version>1.0.0-beta5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
<goal>addScalaSources</goal>
</goals>
<id>default-sbt-compile</id>
</execution>
</executions>
</plugin>
Code	coverage
Cobertura,	Jacoco,	Clover,	EclEmma?!?
Works	good	for	Java
Line	and	branch	coverage
Demo
Let's	try	it	for	Scala!
That's	awful!
Scala	compiler	generates	lots	for	you	(i.e.	in	case	classes,
traits	etc)
Cobertura	and	Jacoco	work	on	byte	code
ergo	lots	of	uncovered	generated	code
I	don't	want	to	be	testing	generated	code,	would	you?
to	the	rescue!
Scala	statement	and	branch	coverage!
scoverage-maven-plugin
Demo
Let's	try	it	for	Scala!
So	what	did	we	do?!
Statement	coverage	for	Scala	with	scoverage
Normal	line/branch	coverage	for	Java	with	Cobertura
Code	quality	using	Sonar
Code	Quality	Platform
Code	metrics
Coverage
Complexity
Size
Rules
Spot	regression
SonarQube
Tooling
docker-compose	script	with	data	container,	Postgres
database	and	SonarQube
Contains	plugins	needed	for	Scala!	(Cobertura,
scoverage,	Java,	etc)
	-	updated	to	use	cobertura	only	for	Java
Used	for	filtering	Scala	coverage	from	cobertura.xml
scala-sonarqube-docker
sonar-scala-plugin
xml-transform-maven-plugin
Demo
Java	&	Scala	code	coverage	in	Sonar
*.java
cobertura
cobertura.xml
*.scala
scoverage
scoverage.xml
xml-transform-maven-plugin
Sonar Scoverage plugincobertura-without-scala.xml
Sonar Cobertura Plugin
SonarQube
More	code	analysis
Compiler	flags	Java
-Xlint:unchecked	-	Unchecked	casts
Compiler	flags	Scala
-unchecked
-deprecation
-feature
-Xlint
-Yno-adapted-args
-Ywarn-dead-code
-Ywarn-numeric-widen
-Ywarn-value-discard
-Xfuture
-Ywarn-unused-import
-Ywarn-unused
Demo
Compiler	flags
FindBugs	&	FindSecurityBugs
More	checks	-	To	implement
Abide
Wartremover
Documentation	for	Java
consumers
Generated	outline	of	Scala	files	in	java
including	javadoc	annotations
useful	to	generate	Javadoc	for	Java	consumers
genjavadoc
Demo
genjavadoc
Wrap	up
Recap
Scala	and	Java	code	in
single	module
multiple	modules
code	coverage	on	both
Code	Quality	with
SonarQube
ScalaStyle
FindBugs
Lots	to	tweak	-	compiler	arguments,	linters
Documentation	for	Java
Thanks	for	listening
Questions?
	/	Slides Code
Important	legal	information
This	document	has	been	produced	by	ING	solely	for	use	at	presentations	held	externally,	and	may	not	be	reproduced	or	redistributed,	in	whole	or	in	part,	to	any	other	persons	without	the	prior	written
consent	of	ING.	The	content	of	this	document	is	not	to	be	construed	as	legal,	business,	investment	or	tax	advice.	Each	person	should	consult	with	its	own	professional	advisors	for	any	such	matters	and
advice.	ING	comprises	a	broad	spectrum	of	companies	(the	"ING	companies"),	many	of	them	operating	under	their	own	brand	names.	Almost	every	ING	company,	business	unit	or	product	group,	has	its
own	website	on	the	internet	where	it	offers	information	about	its	products	and	services.	Reference	is	made	to	those	websites	for	further	details	and	hyperlinks	to	the	websites	of	those	ING	companies,
business	units	and	product	groups,	if	available.	However,	ING	is	not	responsible	for	the	content	of	any	other	websites	that	are	included	in	this	document.	A	link	to	such	website	is	meant	for	convenience
only	and	does	not	imply	that	ING	endorses	the	website	or	any	products	or	services	that	it	describes.	Your	access	to	and	use	of	any	other	websites	included	in	this	document	is	at	your	own	risk	and	ING
assumes	no	obligation	or	liability	in	connection	therewith.
Certain	of	the	statements	contained	in	this	release	are	statements	of	future	expectations	and	other	forward-looking	statements.	These	expectations	are	based	on	management’s	current	views	and
assumptions	and	involve	known	and	unknown	risks	and	uncertainties.	Actual	results,	performance	or	events	may	differ	materially	from	those	in	such	statements	due	to,	among	other	things	:	(1)	changes
in	general	economic	conditions,	in	particular	economic	conditions	in	ING’s	core	markets,	(2)	changes	in	performance	of	financial	markets,	including	developing	markets,	(3)	consequences	of	a	potential
(partial)	break-up	of	the	euro,	(4)	ING’s	implementation	of	the	restructuring	plan	as	agreed	with	the	European	Commission,	(5)	changes	in	the	availability	of,	and	costs	associated	with,	sources	of	liquidity
such	as	interbank	funding,	as	well	as	conditions	in	the	credit	markets	generally,	including	changes	in	borrower	and	counterparty	creditworthiness,	(6)	the	frequency	and	severity	of	insured	loss	events,	(7)
changes	affecting	mortality	and	morbidity	levels	and	trends,	(8)	changes	affecting	persistency	levels,	(9)	changes	affecting	interest	rate	levels,	(10)	changes	affecting	currency	exchange	rates,	(11)
changes	in	investor,	customer	and	policyholder	behaviour,	(12)	changes	in	general	competitive	factors,	(13)	changes	in	laws	and	regulations,	(14)	changes	in	the	policies	of	governments	and/or	regulatory
authorities,	(15)	conclusions	with	regard	to	purchase	accounting	assumptions	and	methodologies,	(16)	changes	in	ownership	that	could	affect	the	future	availability	to	us	of	net	operating	loss,	net	capital
and	built-in	loss	carry	forwards,	(17)	changes	in	credit-ratings,	(18)	ING’s	ability	to	achieve	projected	operational	synergies	and	(19)	the	other	risks	and	uncertainties	detailed	in	the	risk	factors	section
contained	in	the	most	recent	annual	report	of	ING	Groep	N.V.	Any	forward-looking	statements	made	by	or	on	behalf	of	ING	speak	only	as	of	the	date	they	are	made,	and,	ING	assumes	no	obligation	to
publicly	update	or	revise	any	forward-looking	statements,	whether	as	a	result	of	new	information	or	for	any	other	reason.
This	document	does	not	constitute	an	offer	to	sell,	or	a	solicitation	of	an	offer	to	purchase,	any	securities	in	the	United	States	or	any	other	jurisdiction.	The	securities	of	NN	Group	have	not	been	and	will
not	be	registered	under	the	U.S.	Securities	Act	of	1933,	as	amended	(the	“Securities	Act”),	and	may	not	be	offered	or	sold	within	the	United	States	absent	registration	or	an	applicable	exemption	from	the
registration	requirements	of	the	Securities	Act.
www.ing.com

Introducing Scala in your existing Java project