@@ -23,61 +23,29 @@ Hence we will provide a quick tutorial that gives you the first taste of it.
2323Before tackling this tutorial, make sure you have the [ Gradle] ( https://gradle.org ) build tool
2424[ installed] ( https://gradle.org/install/ ) and available on your machine.
2525
26- ## Create a Gradle Java Project
26+ ## Create a Simple Initial Gradle Java Project
2727
28- Let’s assume in this case that we start off with a very simple default Gradle Java application
29- that we create from a command-line window with the instruction below.
28+ Let’s assume in this case that we start off with a very simple Gradle Java application
29+ that we create from a command-line window with the instructions below.
3030
3131``` shell
32- gradle init --type java-application --dsl groovy
32+ mkdir 5-minute-tutorial
33+ cd 5-minute-tutorial
34+ echo " " > settings.gradle
3335```
3436
35- Gradle will ask you some details about your application. The conversation is shown below
36- for completenes but of course you can make your own choices.
37-
38- ``` shell
39- Enter target Java version (min: 7, default: 21):
40-
41- Project name (default: 5-minute-tutorial):
42-
43- Select application structure:
44- 1: Single application project
45- 2: Application and library project
46- Enter selection (default: Single application project) [1..2] 1
47-
48- Select test framework:
49- 1: JUnit 4
50- 2: TestNG
51- 3: Spock
52- 4: JUnit Jupiter
53- Enter selection (default: JUnit Jupiter) [1..4] 4
54-
55- Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no]
37+ The last line above created an empty ` settings.gradle ` file. To use Gradle, we also need
38+ a ` build.gradle ` file.
5639
40+ ## Create the ` build.gradle ` file
5741
58- > Task :init
59- Learn more about Gradle by exploring our Samples at https://docs.gradle.org/8.13/samples/sample_building_java_applications.html
42+ Add a ` build.gradle ` file to the ` 5-minute-tutorial ` folder.
6043
61- BUILD SUCCESSFUL in 19s
62- 1 actionable task: 1 executed
44+ ``` shell
45+ echo " " > build.gradle
6346```
6447
65- Now you should see two folders along with a number of Gradle specific files that have
66- been created. It is beyond the scope of this short tutorial to explain all these artefacts.
67- However, we will focus on the ` build.gradle ` file in the ` app ` folder.
68-
69- ## Modify the generated ` app\build.gradle ` file
70-
71- We have to specify the use of the Gradle plugin in the ` plugin ` section of the ` build.gradle ` file.
72- So we add ` id('org.hibernate.tool.hibernate-tools-gradle') version '7.0.3.Final' ` to that section.
73-
74- Also we need to depend on the java library containing the [ H2 database] ( ) drivers.
75- This is done in the ` dependencies ` section of the ` gradle.build ` file,
76- to which we add ` implementation('com.h2database:h2:2.3.232') ` .
77- To be able to look up this dependency, we add ` mavenCentral() ` to the ` repositories ` section
78- of the ` gradle.build ` file.
79-
80- The complete ` gradle.build ` file can look like the below.
48+ Now edit the created emtpy file and add the following contents:
8149
8250``` groovy
8351plugins {
@@ -104,7 +72,15 @@ For the purpose of this tutorial introduction, let's assume that you have a data
10472[ H2 Sakila database] ( https://github.com/hibernate/sakila-h2 ) reacheable at the following JDBC URL:
10573` jdbc:h2:tcp://localhost/./sakila ` .
10674
107- With this set up, the ` hibernate.properties ` file should contain the properties as specified below.
75+ With this set up, we create a ` hibernate.properties ` file in the ` src/main/resources ` folder
76+ as this is the default location where the Hibernate Gradle plugin will look for this file.
77+
78+ ``` shell
79+ mkdir -p src/main/resources
80+ echo " " > src/main/resources/hibernate.properties
81+ ```
82+
83+ Now edit the ` hibernate.properties ` file so that it contains the properties as specified below.
10884
10985``` properties
11086hibernate.connection.driver_class =org.h2.Driver
@@ -114,6 +90,25 @@ hibernate.default_catalog=SAKILA
11490hibernate.default_schema =PUBLIC
11591```
11692
117- For the file to be found by the plugin, add it as a resource to the project in the
118- ` app/src/main/resources ` subfolder.
93+ Now we are ready to generate the entities.
94+
95+ ## Run the Reverse Engineering
96+
97+ With all the previous elements in place, generating the Java classes from the Sakila database
98+ becomes as simple as issuing ` gradle generateJava ` in your command line window.
99+
100+ ``` shell
101+ > Task :generateJava
102+ Starting Task ' generateJava'
103+ Creating Java exporter
104+ Loading the properties file : /Users/koen/temp/5-minute-tutorial/src/main/resources/hibernate.properties
105+ Properties file is loaded
106+ Starting Java export to directory: /Users/koen/temp/5-minute-tutorial/generated-sources...
107+ ...
108+ Java export finished
109+ Ending Task ' generateJava'
110+ ```
111+
119112
113+ Congratulations! You have succesfully created Java classes for the Sakila database... Now it's
114+ probably time to dive somewhat deeper in the available functionality.
0 commit comments