ebook img

sbt in Action: The simple Scala build tool PDF

282 Pages·2015·6.24 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview sbt in Action: The simple Scala build tool

The simple Scala build tool Joshua Suereth Matthew Farwell M A N N I N G www.it-ebooks.info sbt in Action Licensed to tracwy wmwo.oitr-ee b<[email protected]> Licensed to tracwy wmwo.oitr-ee b<[email protected]> sbt in Action THE SIMPLE SCALA BUILD TOOL JOSHUA SUERETH MATTHEW FARWELL MANNING SHELTER ISLAND Licensed to tracwy wmwo.oitr-ee b<[email protected]> For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: [email protected] ©2016 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Development editor: Jennifer Stout Technical development editors: Patrick Touhey, Matt Momont Manning Publications Co. Copyeditors: Tiffany Taylor, 20 Baldwin Road Linda Recktenwald PO Box 761 Proofreader: Melody Dolab Shelter Island, NY 11964 Technical proofreader: Thomas Lockney Typesetter: Dottie Marsico Cover designer: Marija Tudor ISBN 9781617291272 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 20 19 18 17 16 15 Licensed to tracwy wmwo.oitr-ee b<[email protected]> contents preface xi acknowledgments xiii about this book xv about the cover illustration xviii PART 1 WHY SBT?...........................................................1 1 Why sbt? 3 1.1 Why a build tool? 4 1.2 Apache Ant 6 1.3 Apache Maven 8 Build definition 8 ■ Maven workflow—default lifecycle 9 Adding another task to a Maven build 11 ■ Advantages of Maven 11 ■ Limitations of Maven 11 1.4 Gradle 12 What is Gradle? 12 ■ Gradle workflow 13 ■ Adding another task to a Gradle build 13 ■ Advantages of Gradle 14 Limitations of Gradle 14 1.5 Why sbt? 15 How sbt works 15 ■ Plugin architecture vs. tasks 16 Phases vs. task dependencies 18 ■ Passing information around your build 18 ■ Working with Scala 19 ■ Multiproject builds 20 ■ Dependency resolution 21 v Licensed to tracwy wmwo.oitr-ee b<[email protected]> vi CONTENTS 1.6 Interactivity/reactivity of sbt 21 Quicker compilation and testing cycle 21 ■ Quicker compilation and testing cycle 21 ■ sbt and the Scala REPL—the console command 22 1.7 Summary 23 2 Getting started 24 2.1 Setting up sbt 25 Setting the PATH in bash (for Linux/Mac) 25 Running sbt 26 2.2 Setting up a build 27 Tasks 28 ■ Settings 29 2.3 Running code 31 2.4 Testing code 35 Running tasks when sources change 37 ■ Selecting tests with interactive tasks 38 2.5 Summary 39 PART 2 UNDERSTANDING SBT’S CORE CONCEPTS............41 3 Core concepts 43 3.1 Creating builds 44 3.2 Defining settings 44 Initializations 47 3.3 Creating and executing tasks 49 Task dependencies 52 3.4 Using configurations 54 3.5 Defining with subprojects 55 3.6 Putting it all together 60 3.7 Summary 64 4 The default build 66 4.1 Compiling your code 67 4.2 Finding your sources 68 Standard organization of sources 68 ■ Testing sources 71 Custom organization of sources 72 ■ Filtering the source you want 74 Licensed to tracwy wmwo.oitr-ee b<[email protected]> CONTENTS vii 4.3 Depending on libraries 75 Unmanaged dependencies 76 ■ Managed dependencies 76 Managed dependencies and configurations 79 4.4 Packaging your project 80 Identifying your project 82 4.5 Summary 83 PART 3 WORKING WITH SBT ...........................................85 5 Testing 87 5.1 Configuring specs2 with sbt 88 Reports and forking tests 90 ■ Digging deeper: other options for forking 93 5.2 JUnit and using custom code 94 Report generation with JUnit 95 5.3 ScalaCheck 98 5.4 Integration testing 102 ScalaTest and Selenium 102 ■ Challenges of integration testing 104 ■ Adding integration tests to sbt 105 5.5 Summary 109 6 The IO and Process libraries 110 6.1 Packaging using processes 111 6.2 Packaging using the sbt.IO library 114 6.3 More mappings 116 6.4 Task dependencies 118 6.5 Logging using the sbt logger 119 6.6 Running your build using fork 121 6.7 Linking everything together: dependencies 122 6.8 Linking everything together: processes 124 6.9 Summary 127 7 Accepting user input 128 7.1 Accepting user input with input tasks 130 7.2 Defining an interface with parsers 133 7.3 Defining a database evolution parser 136 Licensed to tracwy wmwo.oitr-ee b<[email protected]> viii CONTENTS 7.4 Helping the user with autocomplete 142 7.5 Summary 144 8 Using plugins and external libraries 146 8.1 Using plugins to check your code 147 8.2 Using the Revolver plugin to restart the application 151 8.3 Creating your uber jar using the assembly plugin 153 8.4 Including a library in your plugin build 155 8.5 Adding a plugin for use in all of your projects— signing your projects 159 8.6 Adding local credentials for deployment 161 8.7 Summary 161 9 Debugging your build 162 9.1 Running sbt 163 9.2 Making your build compile 165 9.3 Ensuring tasks are run 168 9.4 Resolving dependency conflicts 172 Fixing resolution failures 173 ■ Fixing resolution conflicts 175 9.5 Summary 179 PART 4 EXTENDING SBT ...............................................181 10 Automating workflows with commands 183 10.1 Creating a simple command 184 10.2 Running tasks in parallel 186 10.3 Parsing input with commands 187 10.4 Creating useful help messages 194 10.5 Summary 197 11 Defining a plugin 198 11.1 Reusing code using Scala files 200 11.2 Introducing the AutoPlugin interface 200 Taking a closer look—the plugin definition 203 Taking a closer look—task and setting dependencies 204 11.3 Testing a plugin with the scripted plugin 206 Licensed to tracwy wmwo.oitr-ee b<[email protected]> CONTENTS ix 11.4 Using configurations in your plugin 211 11.5 Adding incremental tasks 215 Adding incremental tasks with .previous—a sneak preview of 1.0 217 11.6 Making things easy for the user—more about the AutoPlugin interface 218 11.7 Summary 222 PART 5 DEPLOYING YOUR PROJECTS.............................223 12 Distributing your projects 225 12.1 Publishing a library 226 12.2 Publishing locally 229 12.3 Publishing a simple server 230 12.4 Generating a distribution 232 12.5 Creating a Linux distribution 236 12.6 Summary 239 appendix A What you need to know about Ivy 240 appendix B Migrating to autoplugins 251 appendix C Advanced setting/task API 254 index 257 Licensed to tracwy wmwo.oitr-ee b<[email protected]>

Description:
A tutorial about effectively building Scala projects, sbt in Action introduces the sbt tool with a simple project that establishes the fundamentals of running commands and tasks. Next, it shows you how to use the peripheral libraries in sbt to make common tasks simpler. Finally, it covers how to dep
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.