Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions gradle/docs/5-minute-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,59 @@ Learn more about Gradle by exploring our Samples at https://docs.gradle.org/8.13
BUILD SUCCESSFUL in 19s
1 actionable task: 1 executed
```

Now you should see two folders along with a number of Gradle specific files that have
been created. It is beyond the scope of this short tutorial to explain all these artefacts.
However, we will focus on the `build.gradle` file in the `app` folder.

## Modify the generated `app\build.gradle` file

We have to specify the use of the Gradle plugin in the `plugin` section of the `build.gradle` file.
So we add `id('org.hibernate.tool.hibernate-tools-gradle') version '7.0.3.Final'` to that section.

Also we need to depend on the java library containing the [H2 database]() drivers.
This is done in the `dependencies` section of the `gradle.build` file,
to which we add `implementation('com.h2database:h2:2.3.232')`.
To be able to look up this dependency, we add `mavenCentral()` to the `repositories` section
of the `gradle.build` file.

The complete `gradle.build` file can look like the below.

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```groovy

That is if you decide to go with the highlights 😃

plugins {
id('application')
id('org.hibernate.tool.hibernate-tools-gradle') version '7.0.3.Final'
}

repositories {
mavenCentral()
}

dependencies {
implementation('com.h2database:h2:2.3.232')
}
```

With this in place, we need to make sure that the Hibernate Tools Gradle plugin knows where
to find the database from which to generate the artefacts. This is done by spefifying the
Hibernate properties in the file `hibernate.properties`.

## Specify the Hibernate Properties

For the purpose of this tutorial introduction, let's assume that you have a database running, e.g.
[H2 Sakila database](https://github.com/hibernate/sakila-h2) reacheable at the following JDBC URL:
`jdbc:h2:tcp://localhost/./sakila`.

With this set up, the `hibernate.properties` file should contain the properties as specified below.

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```properties

and I think it's properties for the property files 🙈 (same if you decide to do the highlights 😃 )

hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila
hibernate.connection.username=sa
hibernate.default_catalog=SAKILA
hibernate.default_schema=PUBLIC
```

For the file to be found by the plugin, add it as a resource to the project in the
`app/src/main/resources` subfolder.

39 changes: 4 additions & 35 deletions gradle/docs/examples/5-minute-tutorial/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.13/userguide/building_java_projects.html in the Gradle documentation.
*/

plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id('application')
id('org.hibernate.tool.hibernate-tools-gradle') version '7.0.3.Final'
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// Use JUnit Jupiter for testing.
testImplementation libs.junit.jupiter

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// This dependency is used by the application.
implementation libs.guava
}

// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

application {
// Define the main class for the application.
mainClass = 'org.example.App'
}

tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
implementation('com.h2database:h2:2.3.232')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw.. I know that Steve is in favor of using these version catalogs (hibernate/hibernate-reactive#1989), but I'm not sure how applicable is that for a small tutorial 😃 🙈

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
############################################################################
# Hibernate Tools, Tooling for your Hibernate Projects #
# #
# Copyright 2004-2025 Red Hat, Inc. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" basis, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
############################################################################
hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:tcp://localhost/./sakila
hibernate.connection.username=sa
hibernate.default_catalog=SAKILA
hibernate.default_schema=PUBLIC