1 00:00:00,000 --> 00:00:04,700 [MUSIC] 2 00:00:04,700 --> 00:00:07,650 Hello, I'm Craig and I'm a developer. 3 00:00:07,650 --> 00:00:10,910 In this workshop, I'm going to show you one approach of how you can manage 4 00:00:10,910 --> 00:00:13,190 your project dependencies in Java. 5 00:00:13,190 --> 00:00:15,420 If you don't know what dependencies are or 6 00:00:15,420 --> 00:00:18,950 why you'd want to manage them, don't worry, we'll go over that too. 7 00:00:18,950 --> 00:00:23,140 We're going to be doing a quick drive-by of a popular bill tool called Gradle, 8 00:00:23,140 --> 00:00:26,560 which we will use to explore the world of dependency management. 9 00:00:26,560 --> 00:00:29,770 You'll pick up enough skills to become comfortable with the amazing tool, and 10 00:00:29,770 --> 00:00:31,460 I'll direct you where to get more information. 11 00:00:32,640 --> 00:00:33,970 Before we get started, 12 00:00:33,970 --> 00:00:37,720 let me remind you that there are teacher's notes attached to each video. 13 00:00:37,720 --> 00:00:40,550 I'll use this area to point out more detailed information than we 14 00:00:40,550 --> 00:00:41,950 cover in the video. 15 00:00:41,950 --> 00:00:46,230 For instance, on this video, I've added some recommended prerequisites. 16 00:00:46,230 --> 00:00:48,000 And remember, if I'm talking to fast, 17 00:00:48,000 --> 00:00:52,600 you can always slow me way down using the video controls. 18 00:00:52,600 --> 00:00:53,455 Totally cool by me. 19 00:00:53,455 --> 00:00:56,000 Okay, so let's get started. 20 00:00:57,000 --> 00:00:59,130 I know you love coding, but 21 00:00:59,130 --> 00:01:03,780 you don't really wanna have to code every single thing all the time, right? 22 00:01:03,780 --> 00:01:06,190 Like, if you were setting out to build a website, 23 00:01:06,190 --> 00:01:08,450 you wouldn't want to write the framework. 24 00:01:08,450 --> 00:01:11,850 You'd wanna use and existing one like Spring MVC or Play. 25 00:01:11,850 --> 00:01:13,880 You wouldn't write your own, right? 26 00:01:13,880 --> 00:01:16,530 Well this is one example of a dependency. 27 00:01:16,530 --> 00:01:18,580 You would depend on that web framework. 28 00:01:20,130 --> 00:01:22,980 What if I told you that there was a whole world of these projects that 29 00:01:22,980 --> 00:01:24,340 you could depend on? 30 00:01:24,340 --> 00:01:28,280 What if I told you that a majority of them were free to use, well documented, 31 00:01:28,280 --> 00:01:30,860 and very easy to implement? 32 00:01:30,860 --> 00:01:34,410 What if I then told you that you could also see the source code and 33 00:01:34,410 --> 00:01:36,800 learn exactly how it was developed? 34 00:01:36,800 --> 00:01:37,310 Well you can. 35 00:01:37,310 --> 00:01:41,260 And what I'm talking about is Open Source Software, and you can and 36 00:01:41,260 --> 00:01:42,530 should depend on it. 37 00:01:42,530 --> 00:01:44,020 And in this workshop, I'll show you how. 38 00:01:45,350 --> 00:01:50,170 The idea behind open source software is one of collaboration and transparency. 39 00:01:50,170 --> 00:01:52,100 More of its history is in the teacher's notes. 40 00:01:52,100 --> 00:01:55,250 But what I want you to know here is that just like how you would like to not 41 00:01:55,250 --> 00:01:59,210 have to write all this code yourself, the same is true for those people who write 42 00:01:59,210 --> 00:02:02,230 these open source projects, or libraries, as they're commonly called. 43 00:02:03,410 --> 00:02:06,970 When a dependency that you are using requires another library, 44 00:02:06,970 --> 00:02:10,310 the required library is known as a transitive dependency. 45 00:02:11,630 --> 00:02:15,650 Essentially, what this means to you is that you also rely on that 46 00:02:15,650 --> 00:02:16,470 other dependency. 47 00:02:17,700 --> 00:02:19,991 The Java language is a big supporter of open source. 48 00:02:19,991 --> 00:02:26,464 In fact, the Java language itself and most implementations of the JDK are 99% open. 49 00:02:26,464 --> 00:02:30,307 You can find just about any tool you need out there, and it's available for 50 00:02:30,307 --> 00:02:30,860 your use. 51 00:02:32,460 --> 00:02:34,760 So let's say that you're working on a project, and 52 00:02:34,760 --> 00:02:39,650 you'd like to write data out into a comma separated value, or CSV format, so 53 00:02:39,650 --> 00:02:42,100 that it can be imported into a spreadsheet. 54 00:02:42,100 --> 00:02:44,760 Well you might be tempted to write your own. 55 00:02:44,760 --> 00:02:46,690 But then when you start thinking about it, 56 00:02:46,690 --> 00:02:48,510 you start thinking about all the edge cases. 57 00:02:48,510 --> 00:02:52,230 Like what happens if the value contains a comma? 58 00:02:52,230 --> 00:02:55,080 What other kinds of bugs might we be missing? 59 00:02:55,080 --> 00:02:57,520 There is a great saying that comes from the open source community and 60 00:02:57,520 --> 00:03:01,230 it states this, given enough eyeballs, all bugs are shallow. 61 00:03:01,230 --> 00:03:02,760 You'll find this surprisingly true. 62 00:03:03,860 --> 00:03:07,910 The good news is you don't have to write the CSV code yourself. 63 00:03:07,910 --> 00:03:11,520 There is a library that has thought through all of the edge cases and 64 00:03:11,520 --> 00:03:14,000 made it possible for you to just use their code. 65 00:03:14,000 --> 00:03:18,610 It's part of the Apache Commons library and there is a class called CSV Writer. 66 00:03:18,610 --> 00:03:19,360 Pretty handy, right? 67 00:03:20,540 --> 00:03:21,930 So how do you use it? 68 00:03:21,930 --> 00:03:25,630 Well, you could just download that Java archive, or jar file, and 69 00:03:25,630 --> 00:03:27,922 put its files in your class path. 70 00:03:27,922 --> 00:03:31,960 But it's possible that the library has transitive definitives as well. 71 00:03:31,960 --> 00:03:35,160 We'd also need to go get those, and the other dependent jars. 72 00:03:35,160 --> 00:03:38,440 Oh, also, I guess we'd have to put those jars in some place into a shared 73 00:03:38,440 --> 00:03:40,220 code base so others could also use the code. 74 00:03:41,280 --> 00:03:44,279 This is starting to sound unwieldy, isn't it, and not very productive at all. 75 00:03:45,460 --> 00:03:48,600 Surely, there must be a better way, right? 76 00:03:48,600 --> 00:03:51,690 Well, the good news is there's several ways to solve this problem. 77 00:03:51,690 --> 00:03:55,720 Let's walk through the increasingly popular way of solving this problem. 78 00:03:55,720 --> 00:03:59,880 We'll use Gradle, the build automation tool to manage our dependency and 79 00:03:59,880 --> 00:04:01,680 do as they promise, build happiness.