Recommended usage/configuration of Intellij with Gradle projects (war, jar) to be deployed on Wildfly Servers
Hello. Dealing with Gradle based projects in IntelliJ I was wondering whether there are some best practices/recommendations how to setup and configure the toolset. Currently mainly working on Java EE7 projects (JSF 2.2, war deployments, often jar dependencies, Lombok via freefair.io) with Intellij 2021.1.1 and Gradle Version 7.0 (or earlier) with a locally running RedHat EAP 7 version.
1. What is the recommended way of creating such a gradle project. A command line gradle init or by means of Intellij?
2. Given the fact that other developers are using Eclipse should I even use something like "idea" plugin in gradle? I usually do not prefer to have IDE specific plugins within a build environment like Gradle. From my opinion it should work without those plugins and the IDE should anyway create it's required stuff around the project when importing/creating the project.
3. Intellij Settings > Gradle Options "Build and run"/"Run tests using": According to Intellij "Gradle" is Default, but with this setting, exploded war is not created which I have configured for Hot Deployment based on some older Stackoverflow information. So both options I have set to "Intellij" for war and jar projects.
4. When importing a Gradle Project to Intellij at least with the 2021 Versions of Intellij I always get "Gradle JVM" errors which I can not remember from earlier Intellij Versions. Seams that configuration of Gradle JVM is set to org.gradle.java.home which fails. Maybe I am missing some environmental parameter. Setting it to "Project SDK" solves the issue however.
5. Now what are the recommended ways for artifact deployment on Wildfly/EAP servers to support hot deployment? What I usually have (based on some older stackoverflow information) is:
- "Build and run using Intellij/Run Tests Using Intellij". With Gradle setting the exploded war is not created which is needed for deployment.
The rest of the gradle settings is shown in Upload id: 2021_05_27_Jbk2prDdodKz51NP - This (2021_05_27_X5fAPbsMP9JZxfEg) is what I usually have configured for Run Configuratoin. Basically these settings seem to work, still I wonder whether this is the best way to support hot deployment.
- With these settings build and deployment via the exploded war (Intellij creates a filesystem configuration in standalone.xml and does not physically deploy the war to the server) basically works but I noticed, that there is a dependency to the "out"-folder created by Intellij builds. I accidentially deleted this folder and after that the deployment to the server was incomplete (resource bundles, configs were missing in the exploded war folder), so trying to access the application in the browser resultet in server errors. In the area "Before launch" in "Run Configurations" both "build" and "build gradle exploded war" are set, so should the out-folder not be created by the build task?
- Btw.: I do not use any exploded war task in gradle by now. Should I do so to use Gradle as the default "build and run tool"? The war task is configured only to set archiveFileName and manifest.
Thx
Rob
Please sign in to leave a comment.
>Currently mainly working on Java EE7 projects (JSF 2.2, war deployments, often jar dependencies, Lombok via freefair.io) with Intellij 2021.1.1 and Gradle Version 7.0 (or earlier) with a locally running RedHat EAP 7 version.
>
>1. What is the recommended way of creating such a gradle project. A command line gradle init or by means of Intellij?
Use Java Enterprise project type in the New Project IDE Wizard and select Gradle based project, then select the frameworks you are going to use. IDE will add corresponding Gradle dependencies and Gradle plugins if needed.
>2. Given the fact that other developers are using Eclipse should I even use something like "idea" plugin in gradle? I usually do not prefer to have IDE specific plugins within a build environment like Gradle. From my opinion it should work without those plugins and the IDE should anyway create it's required stuff around the project when importing/creating the project.
Using idea Gradle plugin is not recommended. It may in some cases produce not compatible with current IDE version configuration. It is indeed supposed and is expected that native IDE Gradle integration should work out of the box.
>3. Intellij Settings > Gradle Options "Build and run"/"Run tests using": According to Intellij "Gradle" is Default, but with this setting, exploded war is not created which I have configured for Hot Deployment based on some older Stackoverflow information. So both options I have set to "Intellij" for war and jar projects.
Indeed, currently IDE artifacts are not built if Delegate to Gradle option is used. I hope it will be fixed in foreseen future. Please vote and follow this issue: https://youtrack.jetbrains.com/issue/IDEA-176700 Please also see a workaround how you can manually create a Gradle task which you can configure to run before deployment of the artifact into application server (in Before launch section).
>4. When importing a Gradle Project to Intellij at least with the 2021 Versions of Intellij I always get "Gradle JVM" errors which I can not remember from earlier Intellij Versions. Seams that configuration of Gradle JVM is set to org.gradle.java.home which fails. Maybe I am missing some environmental parameter. Setting it to "Project SDK" solves the issue however.
Sounds like the https://youtrack.jetbrains.com/issue/IDEA-269983 Where do you have `org.gradle.java.home` option configured?
>Now what are the recommended ways for artifact deployment on Wildfly/EAP servers to support hot deployment? What I usually have (based on some older stackoverflow information) is:
>
>"Build and run using Intellij/Run Tests Using Intellij". With Gradle setting the exploded war is not created which is needed for deployment.
The rest of the gradle settings is shown in Upload id: 2021_05_27_Jbk2prDdodKz51NP
This (2021_05_27_X5fAPbsMP9JZxfEg) is what I usually have configured for Run Configuratoin. Basically these settings seem to work, still I wonder whether this is the best way to support hot deployment.
You can try using manually created Gradle's exploded task with Gradle delegation mode. But if existing natively supported by IDE workflow works for you, I think it it also good.
>With these settings build and deployment via the exploded war (Intellij creates a filesystem configuration in standalone.xml and does not physically deploy the war to the server) basically works but I noticed, that there is a dependency to the "out"-folder created by Intellij builds. I accidentially deleted this folder and after that the deployment to the server was incomplete (resource bundles, configs were missing in the exploded war folder), so trying to access the application in the browser resultet in server errors. In the area "Before launch" in "Run Configurations" both "build" and "build gradle exploded war" are set, so should the out-folder not be created by the build task?
Out folder is created by the build action if gradle delegation is not used. You can check which output paths are used by IDE's build and for artifacts output in corresponding IDE settings:
- Project compiler output
- Module compiler output
- Output directory in the Artifact configuration https://www.jetbrains.com/help/idea/output-layout-tab.html
>Btw.: I do not use any exploded war task in gradle by now. Should I do so to use Gradle as the default "build and run tool"? The war task is configured only to set archiveFileName and manifest.
If you have some complex build logic which IDE's own build can not manage the same way as Gradle, then you should use Gradle delegation mode and in this case it would make sense to try the exploded Gradle task.
Hello, Thx for the detailed answer!
Basically I am currently not depending on Gradle as "Build and Run"-Tool. Setting it to Intellij is absolutely fine for my current requirements. It was only my expectation, that "Gradle" should work as well if it is marked as "Default". Yes: I already commented on and voted for https://youtrack.jetbrains.com/issue/IDEA-176700.
Should I need it I can try it with the workaround. Thx 4 pointing me there.
Concerning the GradleJVM Error: I have checked the .gradle folder (i am on Windows 10) and in the gradle.properties there I have set:
Although ProjectSDK is configured to a slightly later version of openjdk_1.8.0 (212 I think) version 181 is still installed on my machine, so the path is correct. I have voted for https://youtrack.jetbrains.com/issue/IDEA-269983 as well.
Thx
kr Rob
Thank you for the information.