Introducing Scala in your existing Java project
Transcript of Introducing Scala in your existing Java project
IntroducingScalainyourexistingJavaproject
TimSoethout-INGBank
http://blog.timmybankers.nl
OverviewIntroScala@ING-ContextCompilingScalainMavenMixingJavaandScalasourceCodecoverageCodequalityusingSonarMorecodeanalysisDocumentationforJavaconsumersWrapup
WhoamI?TimSoethout
FunctionalprogrammeratheartScalaevangelist/trainerinsideINGMorerecently:Aquariumenthusiast&WestCoastSwing-dancer
Scala@ING
StateMuchJavawithMavenSomeScalaforrestfulservicesusingAkkaOpensource:CoralDevelopersaregettinginterestedandlookingforpossibilities
ContextMavenprojectwritteninJava6TeamwithmixedScalaexperiencelevels
EagertodoScalaButwithinEnterprise:Compliancy
CompilingScalainMaven
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>
MixingJavaandScalasource
DemoMixedJava&Scala
DemoMultiplemodules
MixingitupSeemstoworkonfirstsightProblemscanarisein:
MultiplemodulesDependenciesfromJavatoScalaDependsoncompileordersbtincrementalcompilertotherescue
scala-maven-plugin:
<configuration> <recompileMode>incremental</recompileMode></configuration>
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>
Codecoverage
Cobertura,Jacoco,Clover,EclEmma?!?WorksgoodforJavaLineandbranchcoverage
DemoLet'stryitforScala!
That'sawful!Scalacompilergenerateslotsforyou(i.e.incaseclasses,traitsetc)
CoberturaandJacocoworkonbytecodeergolotsofuncoveredgeneratedcode
Idon'twanttobetestinggeneratedcode,wouldyou?
totherescue!Scalastatementandbranchcoverage!
scoverage-maven-plugin
DemoLet'stryitforScala!
Sowhatdidwedo?!StatementcoverageforScalawithscoverageNormalline/branchcoverageforJavawithCobertura
CodequalityusingSonar
CodeQualityPlatformCodemetrics
CoverageComplexitySizeRules
Spotregression
SonarQube
Tooling
docker-composescriptwithdatacontainer,PostgresdatabaseandSonarQubeContainspluginsneededforScala!(Cobertura,scoverage,Java,etc)
-updatedtousecoberturaonlyforJava
UsedforfilteringScalacoveragefromcobertura.xml
scala-sonarqube-docker
sonar-scala-pluginxml-transform-maven-plugin
DemoJava&ScalacodecoverageinSonar
*.java
cobertura
cobertura.xml
*.scala
scoverage
scoverage.xml
xml-transform-maven-plugin
Sonar Scoverage plugincobertura-without-scala.xml
Sonar Cobertura Plugin
SonarQube
Morecodeanalysis
CompilerflagsJava-Xlint:unchecked-Uncheckedcasts
CompilerflagsScala-unchecked-deprecation-feature-Xlint-Yno-adapted-args-Ywarn-dead-code-Ywarn-numeric-widen-Ywarn-value-discard-Xfuture-Ywarn-unused-import-Ywarn-unused
DemoCompilerflags
FindBugs&FindSecurityBugs
Morechecks-ToimplementAbideWartremover
DocumentationforJavaconsumers
GeneratedoutlineofScalafilesinjavaincludingjavadocannotationsusefultogenerateJavadocforJavaconsumers
genjavadoc
Demogenjavadoc
Wrapup
RecapScalaandJavacodein
singlemodulemultiplemodulescodecoverageonboth
CodeQualitywithSonarQubeScalaStyleFindBugs
Lotstotweak-compilerarguments,lintersDocumentationforJava
ThanksforlisteningQuestions?
/Slides Code
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