README.adoc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. = Vert.x Gradle Starter
  2. This project is a template to start your own Vert.x project using Gradle.
  3. == Prerequisites
  4. * JDK 8+
  5. == Getting started
  6. Create your project with:
  7. [source]
  8. ----
  9. git clone https://github.com/vert-x3/vertx-gradle-starter.git PROJECT_NAME
  10. ----
  11. Replace `PROJECT_NAME` with the name of your project.
  12. On Linux and MacOSx (or Windows with `bash`), if you want to go faster and generate an already configured project run:
  13. [source]
  14. ----
  15. curl http://vertx.io/assets/starter-scripts/create-vertx-project-gradle.sh -o vertx-create-gradle-project.sh; bash vertx-create-gradle-project.sh
  16. ----
  17. == Running the project
  18. Once you have retrieved the project, you can check that everything works with:
  19. [source]
  20. ----
  21. ./gradlew test run
  22. ----
  23. The command compiles the project and runs the tests, then it launches the application, so you can check by yourself. Open your browser to http://localhost:8080. You should see a _Hello World_ message.
  24. == Anatomy of the project
  25. The project contains:
  26. * the Gradle project and its configuration (`build.gradle`)
  27. * a _main_ verticle file (src/main/java/io/vertx/starter/MainVerticle.java)
  28. * a unit test (src/main/test/io/vertx/starter/MainVerticleTest.java)
  29. == Start to hack
  30. 1. Delete the `.git` directory
  31. 2. Open the `build.gradle` file and customize the `version`. You can also change the `mainVerticleName` variable to use your own package name and verticle class.
  32. 3. Run `./gradlew run`.
  33. This last command relaunches Gradle and the application as soon as you change something in `src/main`.
  34. == Building the project
  35. To build the project, just use:
  36. ----
  37. ./gradlew shadowJar
  38. ----
  39. It generates a _fat-jar_ in the `build/libs` directory.
  40. -----------
  41. This project shows how to use the Vert.x 3.2 redeploy feature. Vert.x watches for file changes and will then compile these changes. The hello world verticle will be redeployed automatically.
  42. Simply start the application with:
  43. ./gradlew run
  44. Now point your browser at http://localhost:8080. Then you can make changes to the hello world verticle and reload the browser.
  45. The whole configuration for this is rather simple:
  46. mainClassName = 'io.vertx.core.Launcher'
  47. def mainVerticleName = 'io.vertx.example.HelloWorldVerticle'
  48. // Vert.x watches for file changes in all subdirectories
  49. // of src/ but only for files with .java extension
  50. def watchForChange = 'src/**/*.java'
  51. // Vert.x will call this task on changes
  52. def doOnChange = './gradlew classes'
  53. run {
  54. args = ['run', mainVerticleName, "--redeploy=$watchForChange", "--launcher-class=$mainClassName", "--on-redeploy=$doOnChange"]
  55. }