-
Notifications
You must be signed in to change notification settings - Fork 0
Added gradle conversion doc. #289
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
Draft
EHandtkeBasis
wants to merge
4
commits into
main
Choose a base branch
from
gradle-conversion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| --- | ||
| title: Converting a webforJ Maven Project to Gradle | ||
| sidebar_position: 3 | ||
| description: Learn how to migrate a webforJ project from Maven to Gradle using Groovy Domain Specific Language. | ||
| --- | ||
|
|
||
| # Converting a webforJ maven project to gradle | ||
|
|
||
| If you're working with a webforJ project and looking to switch from Maven to Gradle, this guide walks you through the key changes required to translate a typical `pom.xml` file into a working `build.gradle` script using Groovy Domain Specific Language. The examples are tailored specifically for webforJ setups, including Jetty integration, WAR packaging, and profile-based configuration. | ||
|
|
||
| ## 1. Apply required plugins | ||
|
|
||
| webforJ typically packages the app as a WAR file and runs using Jetty. Enable the following plugins: | ||
|
|
||
| ```groovy | ||
| plugins { | ||
| id 'java' | ||
| id 'war' | ||
| id 'org.gretty' | ||
| } | ||
| ``` | ||
|
|
||
| ## 2. Define project metadata | ||
|
|
||
| These properties match the `<groupId>`, `<artifactId>`, and `<version>` entries from Maven: | ||
|
|
||
| ```groovy | ||
| group = 'org.example' | ||
| version = '1.0-SNAPSHOT' | ||
| ``` | ||
|
|
||
| ## 3. Java version compatibility | ||
|
|
||
| ```groovy | ||
| java { | ||
| toolchain { | ||
| languageVersion.set(JavaLanguageVersion.of(17)) | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## 4. Define repositories | ||
|
|
||
| Include Maven Central and the Sonatype snapshots repository: | ||
|
|
||
| ```groovy | ||
| repositories { | ||
| mavenCentral() | ||
| maven { | ||
| url 'https://s01.oss.sonatype.org/content/repositories/snapshots' | ||
| mavenContent { snapshotsOnly() } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## 5. Declare dependencies | ||
|
|
||
| Replace the `<dependencies>` block from your `pom.xml` with: | ||
|
|
||
| ```groovy | ||
| def webforjVersion = '25.00-SNAPSHOT' | ||
|
|
||
| dependencies { | ||
| implementation "com.webforj:webforj:${webforjVersion}" | ||
| implementation 'org.slf4j:slf4j-simple:2.0.16' | ||
| testImplementation 'com.microsoft.playwright:playwright:1.49.0' | ||
| testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3' | ||
| } | ||
| ``` | ||
|
|
||
| ## 6. Resource and WAR Handling | ||
|
|
||
| You can copy config files as part of your `processResources` phase: | ||
|
|
||
| ```groovy | ||
| def configFile = project.hasProperty('prod') ? 'webforj-prod.conf' : 'webforj-dev.conf' | ||
|
|
||
| tasks.register('copyWebforjConfig', Copy) { | ||
| from "src/main/resources/${configFile}" | ||
| into "$buildDir/resources/main" | ||
| rename { 'webforj.conf' } | ||
| } | ||
|
|
||
| processResources.dependsOn copyWebforjConfig | ||
| ``` | ||
|
|
||
| ## 7. Gretty integration | ||
|
|
||
| Configure your gretty setup, its going to handle the jetty deployment: | ||
|
|
||
| ```groovy | ||
| gretty { | ||
| httpPort = 8080 | ||
| contextPath = '/' | ||
| servletContainer = 'jetty11' | ||
| } | ||
| ``` | ||
|
|
||
| ## 8. Testing | ||
|
|
||
| To enable JUnit 5 (Jupiter), include: | ||
|
|
||
| ```groovy | ||
| test { | ||
| useJUnitPlatform() | ||
| } | ||
| ``` | ||
|
|
||
| ## 9. IDE Integration | ||
|
|
||
| ### IntelliJ IDEA | ||
| - Open the project root folder. | ||
| - IntelliJ will detect `build.gradle` and prompt to import. | ||
| - Ensure the "Use Gradle from wrapper" option is enabled. | ||
|
|
||
| ### Eclipse | ||
| - Install the Buildship Gradle plugin if not already installed. | ||
| - Go to File → Import → Gradle → Existing Gradle Project. | ||
| - Select your project directory and finish. | ||
| <!-- vale off --> | ||
| ### VS Code | ||
| <!-- vale on --> | ||
| - Install the Java Extension Pack. | ||
| - Open the folder, and VS Code will detect the Gradle project. | ||
| - Use the Gradle Tasks tab or command palette to build or run tasks. | ||
|
|
||
|
|
||
| ## 10. Running the app | ||
|
|
||
| Since you are using gretty you will need to build a gradle wrapper first. For this purpose run `gradle wrapper`. | ||
| Now you can use `./gradlew appRun` and the task will utilize the jetty deployment automatically. | ||
|
|
||
| The completed `build.gradle` should look similar to this: | ||
|
|
||
| ```groovy | ||
| plugins { | ||
| id 'java' | ||
| id 'war' | ||
| id 'org.gretty' version '4.1.1' | ||
| } | ||
|
|
||
| group = 'com.gradletest' | ||
| version = '1.0-SNAPSHOT' | ||
|
|
||
| java { | ||
| toolchain { | ||
| languageVersion.set(JavaLanguageVersion.of(21)) | ||
| } | ||
| } | ||
|
|
||
| gretty { | ||
| httpPort = 8080 | ||
| contextPath = '/' | ||
| servletContainer = 'jetty11' | ||
| } | ||
|
|
||
| def webforjVersion = '25.00' | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| maven { | ||
| url 'https://s01.oss.sonatype.org/content/repositories/snapshots' | ||
| mavenContent { snapshotsOnly() } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation "com.webforj:webforj:$webforjVersion" | ||
| implementation 'org.slf4j:slf4j-simple:2.0.16' | ||
|
|
||
| testImplementation 'com.microsoft.playwright:playwright:1.49.0' | ||
| testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3' | ||
| } | ||
|
|
||
| test { | ||
| useJUnitPlatform() | ||
| } | ||
|
|
||
| def configFile = project.hasProperty('prod') ? 'webforj-prod.conf' : 'webforj-dev.conf' | ||
|
|
||
| tasks.register('copyWebforjConfig', Copy) { | ||
| from "src/main/resources/${configFile}" | ||
| into "$buildDir/resources/main" | ||
| rename { 'webforj.conf' } | ||
| } | ||
|
|
||
| processResources.dependsOn 'copyWebforjConfig' | ||
|
|
||
| ``` | ||
| --- | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[Google.Headings] 'VS Code' should use sentence-style capitalization.