|
| 1 | += Building {project-name} apps with Gradle |
| 2 | + |
| 3 | +== Gradle configuration |
| 4 | + |
| 5 | +Configure Gradle as indicated in the link:gradle-config.html[Gradle configuration page]. |
| 6 | + |
| 7 | +At the moment there is no way of automatically generating a new project using the {project-name} Gradle plugin, |
| 8 | +luckily setting up a {project-name} project with Gradle is very simple. You only need to add the {project-name} Gradle plugin like this: |
| 9 | + |
| 10 | +[source,groovy,subs=attributes+] |
| 11 | +---- |
| 12 | +apply plugin: 'io.quarkus.gradle.plugin' |
| 13 | +---- |
| 14 | +Note: If you did not follow the steps indicated in the link:gradle-config.html[Gradle configuration page] |
| 15 | +you need to add this block to your 'build.gradle' file as well: |
| 16 | + |
| 17 | +[source,groovy,subs=attributes+] |
| 18 | +---- |
| 19 | +buildscript { |
| 20 | + repositories { |
| 21 | + mavenCentral() |
| 22 | + } |
| 23 | + dependencies { |
| 24 | + classpath 'io.quarkus:quarkus-gradle-plugin:{quarkus-version}' |
| 25 | + } |
| 26 | +} |
| 27 | +---- |
| 28 | + |
| 29 | +[[project-creation]] |
| 30 | +== Creating a new project |
| 31 | + |
| 32 | +For now we have to manually create a Gradle project file for {project-name}. |
| 33 | +Here is a complete sample file for a simple rest project: |
| 34 | + |
| 35 | +[source,groovy,subs=attributes+] |
| 36 | +---- |
| 37 | +apply plugin: 'java' |
| 38 | +apply plugin: 'maven' |
| 39 | +apply plugin: 'io.quarkus.gradle.plugin' <1> |
| 40 | +
|
| 41 | +
|
| 42 | +group = 'org.acme' |
| 43 | +version = '1.0-SNAPSHOT' |
| 44 | +
|
| 45 | +buildscript { <2> |
| 46 | + repositories { |
| 47 | + mavenCentral() |
| 48 | + } |
| 49 | + dependencies { |
| 50 | + classpath 'io.quarkus:quarkus-gradle-plugin:{quarkus-version}' |
| 51 | + } |
| 52 | +} |
| 53 | +
|
| 54 | +repositories { <3> |
| 55 | + mavenCentral() |
| 56 | +} |
| 57 | +
|
| 58 | +dependencies { <4> |
| 59 | + compileOnly group: 'io.quarkus', name: 'quarkus-resteasy-deployment', version:'{quarkus-version}' |
| 60 | +} |
| 61 | +---- |
| 62 | + |
| 63 | +<1> The {project-name} plugin needs to be applied. |
| 64 | +<2> The buildscript block can be omitted if you added it to your '~/.gradle/init.gradle' file. |
| 65 | +<3> The repositories block can be omitted if you added it to your '~/.gradle/init.gradle' file. |
| 66 | +<4> This dependency is needed for a rest application similar to the getting started example. |
| 67 | + |
| 68 | + |
| 69 | +== Dealing with extensions |
| 70 | + |
| 71 | +From inside a {project-name} project, you can obtain a list of the available extensions with: |
| 72 | + |
| 73 | +[source] |
| 74 | +gradle list-extensions |
| 75 | + |
| 76 | +Functionality to automatically add extensions to your Gradle project is not implemented yet (coming soon). |
| 77 | + |
| 78 | +== Development mode |
| 79 | + |
| 80 | +{project-name} comes with a built-in development mode. |
| 81 | +Run you application with: |
| 82 | + |
| 83 | +[source] |
| 84 | +gradle quarkus-dev |
| 85 | + |
| 86 | +You can then update the application sources, resources and configurations. |
| 87 | +The changes are automatically reflected in your running application. |
| 88 | +This is great to do development spanning UI and database as you see changes reflected immediately. |
| 89 | + |
| 90 | +`quarkus-dev` enables hot deployment with background compilation, which means that when you modify |
| 91 | +your Java files or your resource files and refresh your browser these changes will automatically take effect. |
| 92 | +This works too for resource files like the configuration property file. |
| 93 | +The act of refreshing the browser triggers a scan of the workspace, and if any changes are detected the |
| 94 | +Java files are compiled, and the application is redeployed, then your request is serviced by the |
| 95 | +redeployed application. If there are any issues with compilation or deployment an error page will let you know. |
| 96 | + |
| 97 | +Hit `CTRL+C` to stop the application. |
| 98 | + |
| 99 | +== Debugging |
| 100 | + |
| 101 | +You can run a {project-name} application in debug mode using: |
| 102 | + |
| 103 | +[source] |
| 104 | +gradle quarkus-dev --debug=true |
| 105 | + |
| 106 | +Then, attach your debugger to `localhost:5005`. |
| 107 | + |
| 108 | +== Import in your IDE |
| 109 | + |
| 110 | +Once you have a <<project-creation, project generated>>, you can import it in your favorite IDE. |
| 111 | +The only requirement is the ability to import a Gradle project. |
| 112 | + |
| 113 | +**Eclipse** |
| 114 | + |
| 115 | +In Eclipse, click on: `File -> Import`. |
| 116 | +In the wizard, select: `Maven -> Existing Gradle Project`. |
| 117 | +On the next screen, select the root location of the project. |
| 118 | +The next screen list the found modules; select the generated project and click on `Finish`. Done! |
| 119 | + |
| 120 | +In a separated terminal, run `gradle quarkus-dev`, and enjoy a highly productive environment. |
| 121 | + |
| 122 | +**IntelliJ** |
| 123 | + |
| 124 | +In IntelliJ: |
| 125 | + |
| 126 | +1. From inside IntelliJ select `File -> New -> Project From Existing Sources...` or, if you are on the welcome dialog, select `Import project`. |
| 127 | +2. Select the project root |
| 128 | +3. Select `Import project from external model` and `Gradle` |
| 129 | +4. Next a few times (review the different options if needed) |
| 130 | +5. On the last screen click on Finish |
| 131 | + |
| 132 | +In a separated terminal or in the embedded terminal, run `gradle quarkus-dev`. Enjoy! |
| 133 | + |
| 134 | +**Apache Netbeans** |
| 135 | + |
| 136 | +In Netbeans: |
| 137 | + |
| 138 | +1. Select `File -> Open Project` |
| 139 | +2. Select the project root |
| 140 | +3. Click on `Open Project` |
| 141 | + |
| 142 | +In a separated terminal or the embedded terminal, go to the project root and run `gradle quarkus-dev`. Enjoy! |
| 143 | + |
| 144 | +**Visual Studio Code** |
| 145 | + |
| 146 | +Open the project directory in VS Code. If you have installed the Java Extension Pack (grouping a set of Java extensions), the project is loaded as a Gradle project. |
| 147 | + |
| 148 | +== Building a native image |
| 149 | + |
| 150 | +Native images make {project-name} applications ideal for containers and serverless workloads. |
| 151 | + |
| 152 | +Make sure to have `GRAALVM_HOME` configured and pointing to GraalVM version {graalvm-version}. |
| 153 | + |
| 154 | +Create a native executable using: `gradle quarkus-native`. |
| 155 | +A native executable will be present in `build/`. |
| 156 | + |
| 157 | +=== Build a container friendly executable |
| 158 | + |
| 159 | +The native executable will be specific to your operating system. |
| 160 | +To create an executable that will run in a container, use the following: |
| 161 | + |
| 162 | +[source, bash] |
| 163 | +---- |
| 164 | +gradle quarkus-native --docker-build=true |
| 165 | +---- |
| 166 | + |
| 167 | +The produced executable will be a 64 bit Linux executable, so depending on your operating system |
| 168 | +it may no longer be runnable. |
| 169 | +However, it's not an issue as we are going to copy it to a Docker container. |
| 170 | + |
0 commit comments