-
-
Notifications
You must be signed in to change notification settings - Fork 220
HBX-3022: Create 5 Minute Tutorial for Gradle #5232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <!-- | ||
| ~ 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. | ||
| --> | ||
|
|
||
| [](https://tools.hibernate.org) | ||
|
|
||
| # Hibernate Tools Gradle : 5 Minute Tutorial | ||
|
|
||
| The best way to get to know the Hibernate Tools Gradle plugin is to start to use it. | ||
| Hence we will provide a quick tutorial that gives you the first taste of it. | ||
| Before tackling this tutorial, make sure you have the [Gradle](https://gradle.org) build tool | ||
| [installed](https://gradle.org/install/) and available on your machine. | ||
|
|
||
| ## Create a Gradle Java Project | ||
|
|
||
| Let’s assume in this case that we start off with a very simple default Gradle Java application | ||
| that we create from a command-line window with the instruction below. | ||
|
|
||
| ``` | ||
| gradle init --type java-application --dsl groovy | ||
| ``` | ||
|
|
||
| Gradle will ask you some details about your application. The conversation is shown below | ||
| for completenes but of course you can make your own choices. | ||
|
|
||
| ``` | ||
| Enter target Java version (min: 7, default: 21): | ||
|
|
||
| Project name (default: 5-minute-tutorial): | ||
|
|
||
| Select application structure: | ||
| 1: Single application project | ||
| 2: Application and library project | ||
| Enter selection (default: Single application project) [1..2] 1 | ||
|
|
||
| Select test framework: | ||
| 1: JUnit 4 | ||
| 2: TestNG | ||
| 3: Spock | ||
| 4: JUnit Jupiter | ||
| Enter selection (default: JUnit Jupiter) [1..4] 4 | ||
|
|
||
| Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] | ||
|
|
||
|
|
||
| > Task :init | ||
| Learn more about Gradle by exploring our Samples at https://docs.gradle.org/8.13/samples/sample_building_java_applications.html | ||
|
|
||
| BUILD SUCCESSFUL in 19s | ||
| 1 actionable task: 1 executed | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # | ||
| # https://help.github.com/articles/dealing-with-line-endings/ | ||
| # | ||
| # Linux start script should use lf | ||
| /gradlew text eol=lf | ||
|
|
||
| # These are Windows script files and should use crlf | ||
| *.bat text eol=crlf | ||
|
|
||
| # Binary files should be left untouched | ||
| *.jar binary | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Ignore Gradle project-specific cache directory | ||
| .gradle | ||
|
|
||
| # Ignore Gradle build output directory | ||
| build |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * 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' | ||
| } | ||
|
|
||
| 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() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * This source file was generated by the Gradle 'init' task | ||
| */ | ||
| package org.example; | ||
|
|
||
| public class App { | ||
| public String getGreeting() { | ||
| return "Hello World!"; | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println(new App().getGreeting()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * This source file was generated by the Gradle 'init' task | ||
| */ | ||
| package org.example; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class AppTest { | ||
| @Test void appHasAGreeting() { | ||
| App classUnderTest = new App(); | ||
| assertNotNull(classUnderTest.getGreeting(), "app should have a greeting"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # This file was generated by the Gradle 'init' task. | ||
| # https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties | ||
|
|
||
| org.gradle.configuration-cache=true | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # This file was generated by the Gradle 'init' task. | ||
| # https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format | ||
|
|
||
| [versions] | ||
| guava = "33.3.1-jre" | ||
| junit-jupiter = "5.11.3" | ||
|
|
||
| [libraries] | ||
| guava = { module = "com.google.guava:guava", version.ref = "guava" } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it Gradle that adds Guava automatically? 🙈 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, must be... I just have added the Gradle generated default app There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I saw that it doesn't work (anymore?)... I need to figure out why |
||
| junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip | ||
| networkTimeout=10000 | ||
| validateDistributionUrl=true | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use the "language type" here (and in the output example) to get the "syntax highlights" ? (Then the text looks more colourful 😃)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok sure, good idea!