Skip to content

Commit d9afe0f

Browse files
committed
HBX-3022: Create 5 Minute Tutorial for Gradle
- Create initial 5 minute tutorial document - Add section to create Gradle Java project - Add generated 'docs/examples/5-minute-tutorial' project Signed-off-by: Koen Aers <[email protected]>
1 parent 26ce8b3 commit d9afe0f

File tree

13 files changed

+532
-0
lines changed

13 files changed

+532
-0
lines changed

gradle/docs/5-minute-tutorial.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!--
2+
~ Copyright 2004 - 2025 Red Hat, Inc.
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" basis,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
[![Hibernate](https://static.jboss.org/hibernate/images/hibernate_200x150.png)](https://tools.hibernate.org)
18+
19+
# Hibernate Tools Gradle : 5 Minute Tutorial
20+
21+
The best way to get to know the Hibernate Tools Gradle plugin is to start to use it.
22+
Hence we will provide a quick tutorial that gives you the first taste of it.
23+
Before tackling this tutorial, make sure you have the [Gradle](https://gradle.org) build tool
24+
[installed](https://gradle.org/install/) and available on your machine.
25+
26+
## Create a Gradle Java Project
27+
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.
30+
31+
```
32+
gradle init --type java-application --dsl groovy
33+
```
34+
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+
```
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]
56+
57+
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
60+
61+
BUILD SUCCESSFUL in 19s
62+
1 actionable task: 1 executed
63+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
10+
# Binary files should be left untouched
11+
*.jar binary
12+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* This generated file contains a sample Java application project to get you started.
5+
* 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.
6+
*/
7+
8+
plugins {
9+
// Apply the application plugin to add support for building a CLI application in Java.
10+
id 'application'
11+
}
12+
13+
repositories {
14+
// Use Maven Central for resolving dependencies.
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
// Use JUnit Jupiter for testing.
20+
testImplementation libs.junit.jupiter
21+
22+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
23+
24+
// This dependency is used by the application.
25+
implementation libs.guava
26+
}
27+
28+
// Apply a specific Java toolchain to ease working on different environments.
29+
java {
30+
toolchain {
31+
languageVersion = JavaLanguageVersion.of(21)
32+
}
33+
}
34+
35+
application {
36+
// Define the main class for the application.
37+
mainClass = 'org.example.App'
38+
}
39+
40+
tasks.named('test') {
41+
// Use JUnit Platform for unit tests.
42+
useJUnitPlatform()
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* This source file was generated by the Gradle 'init' task
3+
*/
4+
package org.example;
5+
6+
public class App {
7+
public String getGreeting() {
8+
return "Hello World!";
9+
}
10+
11+
public static void main(String[] args) {
12+
System.out.println(new App().getGreeting());
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* This source file was generated by the Gradle 'init' task
3+
*/
4+
package org.example;
5+
6+
import org.junit.jupiter.api.Test;
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class AppTest {
10+
@Test void appHasAGreeting() {
11+
App classUnderTest = new App();
12+
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file was generated by the Gradle 'init' task.
2+
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
3+
4+
org.gradle.configuration-cache=true
5+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file was generated by the Gradle 'init' task.
2+
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
3+
4+
[versions]
5+
guava = "33.3.1-jre"
6+
junit-jupiter = "5.11.3"
7+
8+
[libraries]
9+
guava = { module = "com.google.guava:guava", version.ref = "guava" }
10+
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)