Dependency Management In

Dependency Management In

www.allitebooks.com www.allitebooks.com Getting Started with SBT for Scala Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: September 2013 Production Reference: 1040913 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78328-267-8 www.packtpub.com Cover Image by Aniket Sawant ([email protected]) www.allitebooks.com www.allitebooks.com About the Author Shiti Saxena is a software engineer with around three years of work experience. She is currently working with Imaginea (a business unit of Pramati). She has also previously worked with Tata Consultancy Services Ltd. and Genpact. A true polyglot, she has experience with various languages including Scala, JavaScript, Java, Python, Perl, and C. She also likes to work with Play Scala and AngularJS. She blogs at http://eraoferrors.blogspot.in and maintains open source projects at GitHub. In her spare time, she loves to travel, watch movies, and likes to spend time playing her piano. www.allitebooks.com Acknowledgments I am indebted to my mother, Nithi, and my sisters, Shaila, Anshu, and Aastha, for their constant support. A special thanks to my cousin, Rohit, for guiding, mentoring, understanding, and pampering me. He made me believe that I could write this book, and supported me when I was finding it difficult to finish. He has always been there for me, irrespective of the time or busy schedule. I would like to thank Jay and Vijay Pullur for starting Pramati, and everyone at Pramati for making it a great place to work. I would like to thank Kalyan and Apurba for their support and guidance. I wouldn't have learned many a thing if it wasn't for them. I would like to thank Mark Harrah and Typesafe, without whose efforts, this technology, and eventually this book, wouldn't have been possible. I thank my friends for being there when I need them. I thank the editors at Packt, Meeta, Joel, and Mohammed Fahad, for being good to me and understanding the difficulties I faced while writing the book. They showed great patience when I was unable to meet the deadlines. I am also thankful to the reviewers, Rohit, Prashant, and Aaruna, for their valuable feedback that helped improve the book. I am grateful to everyone who has in some way or the other helped me reach this stage in my life. Thanks! About the Reviewers Coming from a Statistics background and with a Master's degree in Information Technology, Aaruna Godthi likes taking up challenges. He is a polyglot in the field of programming. He currently works at Pramati Technologies. He has worked a bit on Hadoop and Sentiment analysis (entity extraction and association of sentiment). Currently, he is exploring various JavaScript frameworks including Dojo, Ember, and AngularJS. Other than this, he likes exploring offbeat places. Rohit Rai is a software professional and founder of Tuplejump. With over 10 years of experience in the industry, he has been exposed to a wide variety of languages and platforms. He has been working with Scala for over three years, and he decided to take a whole-hearted dive when Scala became the primary development language for the Tuplejump Data Engineering Platform. He is an active contributor to the open source community and a developer and maintainer of various projects around Scala and SBT including the play-yoman integration, play socket.io plugin, Calliope – the cassandra+spark bridge, and so on. He has also authored the book Socket.IO Real-time Web Application Development, Packt Publishing. First of all, I would like to thank the author and publishers for choosing me to review the book. I would to thank my family, friends, and colleagues for understanding that I have been stealing out time from various activities to meet the book deadlines. Prashant Sharma works for Pramati Technologies, which is an umbrella company under which he is part of a development team at Imaginea. He is an open source contributor at Spark, and has been working on projects based on Scala as both a hobby and as his profession. He has also worked on distributed systems, such as ejabberd in erlang, and also other Java-based RESTful and soap-based web services to build multitenant systems. Academically, he is interested in exploring both functional programming and distributed computing. You can find Prashant's work at GitHub (https://github.com/ScrapCodes) and follow him on Twitter (@ScrapCodes). More on Imaginea (http://imaginea.com/) Imaginea has been at the forefront of technological evolution by developing sophisticated software solutions for both its own customers and the open source community. GitHub: https://github.com/imaginea Table of Contents Preface 1 Chapter 1: Hello World with SBT 5 Why SBT? 6 Installing SBT 7 Installing from a package 8 Installing on Mac 8 Installing SBT manually 8 Creating a new project 9 Compiling, testing, and running your project 11 Going interactive with the SBT shell 12 Triggering SBT commands on saves 13 Summary 14 Chapter 2: .sbt Build Definitions 15 The theory of .sbt 15 The .sbt syntax 16 Understanding keys 18 Keys 20 Setting keys 20 Task keys 21 Input keys 22 Working with scopes 22 Summary 24 Chapter 3: Dependency Management 25 Quick introduction to Maven or Ivy dependency management 26 How Ivy works 26 Resolve 27 Retrieve 28 Publish 28 Table of Contents Dependency management in SBT 28 Automatic dependency management 28 Declaring dependencies in the build definition 29 Dependencies using Maven files 33 Dependencies using Ivy files or Ivy XML 33 Adding JAR files manually 34 Resolvers 35 Summary 38 Chapter 4: Full Build Definitions 39 Build definition project 40 .sbt and .scala 41 Working with full build definitions 42 Multiproject builds 43 Summary 47 Chapter 5: Compile, Test, and Run 49 Commands 49 Logging 53 Forking the JVM 56 Parallel execution 58 SBT scripts and REPL 60 Classpath, sources, and resources 62 Test 64 Summary 68 Index 69 [ ii ] Preface Simple Build Tool, abbreviated to SBT, is a build tool for Scala and Java projects. SBT simplifies the process of developing, building, and maintaining a project. This book will show you how to build a Scala project using SBT Version 0.12.3, and the different ways in which SBT can be set up. What this book covers Chapter 1, Hello World with SBT, introduces SBT, and how to get it up and running with an example. Chapter 2, .sbt Build Definitions, explains the components of a simple .sbt build file. Chapter 3, Dependency Management, explains how project dependencies can be configured in SBT. Chapter 4, Full Build Definitions, introduces the .scala build definition and the scenarios in which it can be extremely useful. Chapter 5, Compile, Test, and Run, explains SBT commands and some configurations which can come in handy when developing an application. What you need for this book All that you need to use this book is a PC with Linux or Windows OS or a Mac, a text editor, and Java 1.6 or later. There are SBT plugins available for various IDEs, but setting it up is completely optional. Preface Who this book is for This book is aimed at developers who want to use SBT to build Scala projects. The readers are expected to know programming in Scala. Conventions In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning: Code words in text are shown as follows: "Create an sbt.bat file." A block of code is set as follows: class IntroSpec extends Specification{ "The phrase 'Never odd or even'" should{ "be a palindrome" in { Introduction.isPalindrome("Never odd or even") must beTrue } } When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold: class IntroSpec extends Specification{ "The phrase 'Never odd or even'" should{ "be a palindrome" in { Introduction.isPalindrome("Never odd or even") must beTrue } } Any command-line input or output is written as follows: >compile [success] Total time: 0 s, completed New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes, for example, appear in the text like this: "Clicking on the Next button moves you to the next screen." [ 2 ] Preface Errata Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    86 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us