From 9fec519ce954d7dd4255177607248f77488dee7b Mon Sep 17 00:00:00 2001 From: Eric Handtke Date: Tue, 22 Apr 2025 12:36:34 +0200 Subject: [PATCH 1/4] Added gradle conversion doc. --- docs/docs/configuration/gradle.md | 137 ++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 docs/docs/configuration/gradle.md diff --git a/docs/docs/configuration/gradle.md b/docs/docs/configuration/gradle.md new file mode 100644 index 000000000..ec5ef5d0a --- /dev/null +++ b/docs/docs/configuration/gradle.md @@ -0,0 +1,137 @@ +--- +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 DSL. +--- + +# 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 DSL. 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' +} +``` + +## 2. Define project metadata + +These properties match the ``, ``, and `` 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 `` 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. Jetty server integration + +If you're using Jetty for local development like in the Maven Jetty plugin setup: + +```groovy +tasks.register('startJetty', JavaExec) { + mainClass = 'org.eclipse.jetty.start.Main' + args = ['jetty:run'] + classpath = sourceSets.main.runtimeClasspath +} + +tasks.register('stopJetty', JavaExec) { + mainClass = 'org.eclipse.jetty.start.Main' + args = ['jetty:stop'] + classpath = sourceSets.main.runtimeClasspath +} +``` + +:::tip +Replace `org.eclipse.jetty.start.Main` with your embedded Jetty class if applicable. +::: + +## 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. + +### VS Code +- 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. + +--- + + From cdaa02dadd40f039807be0431cb00140ae354f49 Mon Sep 17 00:00:00 2001 From: Eric Handtke Date: Wed, 23 Apr 2025 10:31:31 +0200 Subject: [PATCH 2/4] Resolved vale issues. --- docs/docs/configuration/gradle.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/docs/configuration/gradle.md b/docs/docs/configuration/gradle.md index ec5ef5d0a..c30862097 100644 --- a/docs/docs/configuration/gradle.md +++ b/docs/docs/configuration/gradle.md @@ -1,12 +1,12 @@ --- 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 DSL. +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 DSL. The examples are tailored specifically for WebforJ setups, including Jetty integration, WAR packaging, and profile-based configuration. +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 @@ -126,8 +126,9 @@ test { - Install the Buildship Gradle plugin if not already installed. - Go to File → Import → Gradle → Existing Gradle Project. - Select your project directory and finish. - + ### VS Code + - 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. From ddbc2efaa81572764b37def56e6c25851b604bf0 Mon Sep 17 00:00:00 2001 From: Eric Handtke Date: Tue, 13 May 2025 14:23:27 +0200 Subject: [PATCH 3/4] Added full example and gretty section. --- docs/docs/configuration/gradle.md | 86 +++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 16 deletions(-) diff --git a/docs/docs/configuration/gradle.md b/docs/docs/configuration/gradle.md index c30862097..7545d3efd 100644 --- a/docs/docs/configuration/gradle.md +++ b/docs/docs/configuration/gradle.md @@ -16,6 +16,7 @@ WebforJ typically packages the app as a WAR file and runs using Jetty. Enable th plugins { id 'java' id 'war' + id 'org.gretty' } ``` @@ -83,28 +84,18 @@ tasks.register('copyWebforjConfig', Copy) { processResources.dependsOn copyWebforjConfig ``` -## 7. Jetty server integration +## 7. Gretty integration -If you're using Jetty for local development like in the Maven Jetty plugin setup: +Configure your gretty setup, its going to handle the jetty deployment: ```groovy -tasks.register('startJetty', JavaExec) { - mainClass = 'org.eclipse.jetty.start.Main' - args = ['jetty:run'] - classpath = sourceSets.main.runtimeClasspath -} - -tasks.register('stopJetty', JavaExec) { - mainClass = 'org.eclipse.jetty.start.Main' - args = ['jetty:stop'] - classpath = sourceSets.main.runtimeClasspath +gretty { + httpPort = 8080 + contextPath = '/' + servletContainer = 'jetty11' } ``` -:::tip -Replace `org.eclipse.jetty.start.Main` with your embedded Jetty class if applicable. -::: - ## 8. Testing To enable JUnit 5 (Jupiter), include: @@ -133,6 +124,69 @@ test { - 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' + +``` --- From ce3af462df0da0a3621fbf3e7961a67261e9dece Mon Sep 17 00:00:00 2001 From: Eric Handtke Date: Tue, 13 May 2025 14:25:08 +0200 Subject: [PATCH 4/4] corrected webforJ spelling. --- docs/docs/configuration/gradle.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/docs/configuration/gradle.md b/docs/docs/configuration/gradle.md index 7545d3efd..aab2f819a 100644 --- a/docs/docs/configuration/gradle.md +++ b/docs/docs/configuration/gradle.md @@ -1,16 +1,16 @@ --- -title: Converting a WebforJ Maven Project to Gradle +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. +description: Learn how to migrate a webforJ project from Maven to Gradle using Groovy Domain Specific Language. --- -# Converting a WebforJ maven project to gradle +# 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. +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: +webforJ typically packages the app as a WAR file and runs using Jetty. Enable the following plugins: ```groovy plugins {