Dependencies4:02 with Craig Dennis
What are dependencies and why do you want them?
[MUSIC] 0:00 Hello, I'm Craig and I'm a developer. 0:04 In this workshop, I'm going to show you one approach of how you can manage 0:07 your project dependencies in Java. 0:10 If you don't know what dependencies are or 0:13 why you'd want to manage them, don't worry, we'll go over that too. 0:15 We're going to be doing a quick drive-by of a popular bill tool called Gradle, 0:18 which we will use to explore the world of dependency management. 0:23 You'll pick up enough skills to become comfortable with the amazing tool, and 0:26 I'll direct you where to get more information. 0:29 Before we get started, 0:32 let me remind you that there are teacher's notes attached to each video. 0:33 I'll use this area to point out more detailed information than we 0:37 cover in the video. 0:40 For instance, on this video, I've added some recommended prerequisites. 0:41 And remember, if I'm talking to fast, 0:46 you can always slow me way down using the video controls. 0:48 Totally cool by me. 0:52 Okay, so let's get started. 0:53 I know you love coding, but 0:57 you don't really wanna have to code every single thing all the time, right? 0:59 Like, if you were setting out to build a website, 1:03 you wouldn't want to write the framework. 1:06 You'd wanna use and existing one like Spring MVC or Play. 1:08 You wouldn't write your own, right? 1:11 Well this is one example of a dependency. 1:13 You would depend on that web framework. 1:16 What if I told you that there was a whole world of these projects that 1:20 you could depend on? 1:22 What if I told you that a majority of them were free to use, well documented, 1:24 and very easy to implement? 1:28 What if I then told you that you could also see the source code and 1:30 learn exactly how it was developed? 1:34 Well you can. 1:36 And what I'm talking about is Open Source Software, and you can and 1:37 should depend on it. 1:41 And in this workshop, I'll show you how. 1:42 The idea behind open source software is one of collaboration and transparency. 1:45 More of its history is in the teacher's notes. 1:50 But what I want you to know here is that just like how you would like to not 1:52 have to write all this code yourself, the same is true for those people who write 1:55 these open source projects, or libraries, as they're commonly called. 1:59 When a dependency that you are using requires another library, 2:03 the required library is known as a transitive dependency. 2:06 Essentially, what this means to you is that you also rely on that 2:11 other dependency. 2:15 The Java language is a big supporter of open source. 2:17 In fact, the Java language itself and most implementations of the JDK are 99% open. 2:19 You can find just about any tool you need out there, and it's available for 2:26 your use. 2:30 So let's say that you're working on a project, and 2:32 you'd like to write data out into a comma separated value, or CSV format, so 2:34 that it can be imported into a spreadsheet. 2:39 Well you might be tempted to write your own. 2:42 But then when you start thinking about it, 2:44 you start thinking about all the edge cases. 2:46 Like what happens if the value contains a comma? 2:48 What other kinds of bugs might we be missing? 2:52 There is a great saying that comes from the open source community and 2:55 it states this, given enough eyeballs, all bugs are shallow. 2:57 You'll find this surprisingly true. 3:01 The good news is you don't have to write the CSV code yourself. 3:03 There is a library that has thought through all of the edge cases and 3:07 made it possible for you to just use their code. 3:11 It's part of the Apache Commons library and there is a class called CSV Writer. 3:14 Pretty handy, right? 3:18 So how do you use it? 3:20 Well, you could just download that Java archive, or jar file, and 3:21 put its files in your class path. 3:25 But it's possible that the library has transitive definitives as well. 3:27 We'd also need to go get those, and the other dependent jars. 3:31 Oh, also, I guess we'd have to put those jars in some place into a shared 3:35 code base so others could also use the code. 3:38 This is starting to sound unwieldy, isn't it, and not very productive at all. 3:41 Surely, there must be a better way, right? 3:45 Well, the good news is there's several ways to solve this problem. 3:48 Let's walk through the increasingly popular way of solving this problem. 3:51 We'll use Gradle, the build automation tool to manage our dependency and 3:55 do as they promise, build happiness. 3:59
You need to sign up for Treehouse in order to download course files.Sign up