Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Applying the Java Plugin

Get Embed Code
4 Languages

Showing Revision 53 created 05/25/2016 by Udacity Robot.

  1. Applying the Java plugin is simple.
  2. We only need to add a single
    line to our build script.
  3. Now if we run Gradle tasks, we see
    a whole wealth of capabilities that
  4. the Gradle Java plugin can handle for
  5. There are four main tasks we'll
    use most often, assemble, build,
  6. clean and scrolling down a bit
    we'll use the test task as well.
  7. Assemble creates the output
    we're interest in.
  8. This is usually a jar but
    can also be more interesting artifacts.
  9. Check runs any tasks we've set up.
  10. Build depends on both assemble and
  11. Finally, clean deletes
    all the build output.
  12. We've got a trivial Java
    project in this folder,
  13. with a single class called person.
  14. Let's try running Gradle assemble.
  15. Looks like it's done.
  16. Looks like the build directory
    contains another four directories.
  17. Looking in the newly
    created build directory,
  18. we find a classes subdirectory,
    which holds our compiled classes.
  19. And a libs subdirectory,
    which holds our newly created jar.
  20. Now you might be thinking to yourself,
  21. I thought there wasn't
    going to be any magic.
  22. This sure seems like magic.
  23. How did Gradle know where
    to find my source code?
  24. I promise there's no magic.
  25. Gradle just has a lot of
    very sensible defaults.
  26. Like, for instance,
  27. it assumes that your JAVA sources live
    in a folder named source name JAVA.
  28. This, like most everything else
    in Gradle, can be configured,
  29. and we'll show how shortly.
  30. There's another important
    thing to know how to do.
  31. And that's run
    the project we just built.
  32. You might have noticed that the Java
    plug-in doesn't add any tasks for
  33. running your code, and
    that's because the JavaExec task type is
  34. already part of the core
    Gradle functionality.
  35. The main property tells the JavaExec
    task the path of your main class.
  36. And we'll talk about this class
    path property very shortly.
  37. If we go ahead and
    run this task, there we go.
  38. We see our task running, and
  39. then we see a greeting coming
    from our newly compiled Java.