Introducing Scala in your existing Java project

36
Introducing Scala in your existing Java project Tim Soethout - ING Bank http://blog.timmybankers.nl

Transcript of Introducing Scala in your existing Java project

Page 1: Introducing Scala in your existing Java project

IntroducingScalainyourexistingJavaproject

TimSoethout-INGBank

http://blog.timmybankers.nl

Page 2: Introducing Scala in your existing Java project

OverviewIntroScala@ING-ContextCompilingScalainMavenMixingJavaandScalasourceCodecoverageCodequalityusingSonarMorecodeanalysisDocumentationforJavaconsumersWrapup

Page 3: Introducing Scala in your existing Java project

WhoamI?TimSoethout

FunctionalprogrammeratheartScalaevangelist/trainerinsideINGMorerecently:Aquariumenthusiast&WestCoastSwing-dancer

Page 4: Introducing Scala in your existing Java project

Scala@ING

Page 5: Introducing Scala in your existing Java project

StateMuchJavawithMavenSomeScalaforrestfulservicesusingAkkaOpensource:CoralDevelopersaregettinginterestedandlookingforpossibilities

Page 6: Introducing Scala in your existing Java project

ContextMavenprojectwritteninJava6TeamwithmixedScalaexperiencelevels

EagertodoScalaButwithinEnterprise:Compliancy

Page 7: Introducing Scala in your existing Java project

CompilingScalainMaven

Page 8: Introducing Scala in your existing Java project

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>

Page 9: Introducing Scala in your existing Java project

MixingJavaandScalasource

Page 10: Introducing Scala in your existing Java project

DemoMixedJava&Scala

Page 11: Introducing Scala in your existing Java project

DemoMultiplemodules

Page 12: Introducing Scala in your existing Java project

MixingitupSeemstoworkonfirstsightProblemscanarisein:

MultiplemodulesDependenciesfromJavatoScalaDependsoncompileordersbtincrementalcompilertotherescue

scala-maven-plugin:

<configuration> <recompileMode>incremental</recompileMode></configuration>

Page 13: Introducing Scala in your existing Java project

Anotheroption;runssbtunderneathNotreallymaintainedanymore,buthelpedusalot6monthsago

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>

Page 14: Introducing Scala in your existing Java project

Codecoverage

Page 15: Introducing Scala in your existing Java project

Cobertura,Jacoco,Clover,EclEmma?!?WorksgoodforJavaLineandbranchcoverage

Page 16: Introducing Scala in your existing Java project

DemoLet'stryitforScala!

Page 17: Introducing Scala in your existing Java project

That'sawful!Scalacompilergenerateslotsforyou(i.e.incaseclasses,traitsetc)

CoberturaandJacocoworkonbytecodeergolotsofuncoveredgeneratedcode

Idon'twanttobetestinggeneratedcode,wouldyou?

Page 18: Introducing Scala in your existing Java project

totherescue!Scalastatementandbranchcoverage!

scoverage-maven-plugin

Page 19: Introducing Scala in your existing Java project

DemoLet'stryitforScala!

Page 20: Introducing Scala in your existing Java project

Sowhatdidwedo?!StatementcoverageforScalawithscoverageNormalline/branchcoverageforJavawithCobertura

Page 21: Introducing Scala in your existing Java project

CodequalityusingSonar

Page 22: Introducing Scala in your existing Java project

CodeQualityPlatformCodemetrics

CoverageComplexitySizeRules

Spotregression

SonarQube

Page 23: Introducing Scala in your existing Java project

Tooling

docker-composescriptwithdatacontainer,PostgresdatabaseandSonarQubeContainspluginsneededforScala!(Cobertura,scoverage,Java,etc)

-updatedtousecoberturaonlyforJava

UsedforfilteringScalacoveragefromcobertura.xml

scala-sonarqube-docker

sonar-scala-pluginxml-transform-maven-plugin

Page 24: Introducing Scala in your existing Java project

DemoJava&ScalacodecoverageinSonar

*.java

cobertura

cobertura.xml

*.scala

scoverage

scoverage.xml

xml-transform-maven-plugin

Sonar Scoverage plugincobertura-without-scala.xml

Sonar Cobertura Plugin

SonarQube

Page 25: Introducing Scala in your existing Java project

Morecodeanalysis

Page 26: Introducing Scala in your existing Java project

CompilerflagsJava-Xlint:unchecked-Uncheckedcasts

Page 27: Introducing Scala in your existing Java project

CompilerflagsScala-unchecked-deprecation-feature-Xlint-Yno-adapted-args-Ywarn-dead-code-Ywarn-numeric-widen-Ywarn-value-discard-Xfuture-Ywarn-unused-import-Ywarn-unused

Page 28: Introducing Scala in your existing Java project

DemoCompilerflags

FindBugs&FindSecurityBugs

Page 30: Introducing Scala in your existing Java project

DocumentationforJavaconsumers

Page 31: Introducing Scala in your existing Java project

GeneratedoutlineofScalafilesinjavaincludingjavadocannotationsusefultogenerateJavadocforJavaconsumers

genjavadoc

Page 32: Introducing Scala in your existing Java project

Demogenjavadoc

Page 33: Introducing Scala in your existing Java project

Wrapup

Page 34: Introducing Scala in your existing Java project

RecapScalaandJavacodein

singlemodulemultiplemodulescodecoverageonboth

CodeQualitywithSonarQubeScalaStyleFindBugs

Lotstotweak-compilerarguments,lintersDocumentationforJava

Page 36: Introducing Scala in your existing Java project

Importantlegalinformation

ThisdocumenthasbeenproducedbyINGsolelyforuseatpresentationsheldexternally,andmaynotbereproducedorredistributed,inwholeorinpart,toanyotherpersonswithoutthepriorwrittenconsentofING.Thecontentofthisdocumentisnottobeconstruedaslegal,business,investmentortaxadvice.Eachpersonshouldconsultwithitsownprofessionaladvisorsforanysuchmattersandadvice.INGcomprisesabroadspectrumofcompanies(the"INGcompanies"),manyofthemoperatingundertheirownbrandnames.AlmosteveryINGcompany,businessunitorproductgroup,hasitsownwebsiteontheinternetwhereitoffersinformationaboutitsproductsandservices.ReferenceismadetothosewebsitesforfurtherdetailsandhyperlinkstothewebsitesofthoseINGcompanies,businessunitsandproductgroups,ifavailable.However,INGisnotresponsibleforthecontentofanyotherwebsitesthatareincludedinthisdocument.AlinktosuchwebsiteismeantforconvenienceonlyanddoesnotimplythatINGendorsesthewebsiteoranyproductsorservicesthatitdescribes.YouraccesstoanduseofanyotherwebsitesincludedinthisdocumentisatyourownriskandING

assumesnoobligationorliabilityinconnectiontherewith.

Certainofthestatementscontainedinthisreleasearestatementsoffutureexpectationsandotherforward-lookingstatements.Theseexpectationsarebasedonmanagement’scurrentviewsandassumptionsandinvolveknownandunknownrisksanduncertainties.Actualresults,performanceoreventsmaydiffermateriallyfromthoseinsuchstatementsdueto,amongotherthings:(1)changesingeneraleconomicconditions,inparticulareconomicconditionsinING’scoremarkets,(2)changesinperformanceoffinancialmarkets,includingdevelopingmarkets,(3)consequencesofapotential

(partial)break-upoftheeuro,(4)ING’simplementationoftherestructuringplanasagreedwiththeEuropeanCommission,(5)changesintheavailabilityof,andcostsassociatedwith,sourcesofliquiditysuchasinterbankfunding,aswellasconditionsinthecreditmarketsgenerally,includingchangesinborrowerandcounterpartycreditworthiness,(6)thefrequencyandseverityofinsuredlossevents,(7)

changesaffectingmortalityandmorbiditylevelsandtrends,(8)changesaffectingpersistencylevels,(9)changesaffectinginterestratelevels,(10)changesaffectingcurrencyexchangerates,(11)changesininvestor,customerandpolicyholderbehaviour,(12)changesingeneralcompetitivefactors,(13)changesinlawsandregulations,(14)changesinthepoliciesofgovernmentsand/orregulatoryauthorities,(15)conclusionswithregardtopurchaseaccountingassumptionsandmethodologies,(16)changesinownershipthatcouldaffectthefutureavailabilitytousofnetoperatingloss,netcapitalandbuilt-inlosscarryforwards,(17)changesincredit-ratings,(18)ING’sabilitytoachieveprojectedoperationalsynergiesand(19)theotherrisksanduncertaintiesdetailedintheriskfactorssectioncontainedinthemostrecentannualreportofINGGroepN.V.Anyforward-lookingstatementsmadebyoronbehalfofINGspeakonlyasofthedatetheyaremade,and,INGassumesnoobligationto

publiclyupdateorreviseanyforward-lookingstatements,whetherasaresultofnewinformationorforanyotherreason.

Thisdocumentdoesnotconstituteanoffertosell,orasolicitationofanoffertopurchase,anysecuritiesintheUnitedStatesoranyotherjurisdiction.ThesecuritiesofNNGrouphavenotbeenandwillnotberegisteredundertheU.S.SecuritiesActof1933,asamended(the“SecuritiesAct”),andmaynotbeofferedorsoldwithintheUnitedStatesabsentregistrationoranapplicableexemptionfromthe

registrationrequirementsoftheSecuritiesAct.

www.ing.com