I am very new to Gradle and loving it so far.
Any guidance would be greatly appreciated.
Using Intellij, Open Liberty, Gradle
I am able to get struts2-core:2.5.33 working , but when I change the
Implementation to struts2-core:7.0.3, I received this error:
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter was found, but is missing another class
I strongly recommend you switch to Kotlin DSL. By not it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio
Do not use the legacy way to apply plugins by adding them in buildscript block and using apply ..., if that is how “liberty” (whatever that is) documents it, report a documentation bug. That is the discouraged legacy way of applying plugins and you should practically always prefer to apply plugins in the plugins { ... } block instead which also adds them to the classpath automatically if necessary. You should usually never need to use a buildscript { ... } block nowadays, especially not to just use some plugin.
Consider using JVM Toolchains feature to decouple the version you run Gradle with from the version you compile and run your code with instead of relying on using Java 21+ to run Gradle and setting the compatibility values.
Do not use ext / extra properties, they are practically always a work-around for not doing something properly. Actually in your case you do not even use extra properties, you just wrapped those three lines totally unnecessarily into the ext { ... } block where they don’t belong. You just set three properties in the var properties field of the server extension on the liberty extension, you can just move those out, or write them more DSL-y like a liberty block that contains a server block that contains var.'...' = ... lines.
Using explicit dependsOn where on the left-hand side is not a lifecycle task is practically always a code-smell. In most cases it means that you do not have task outputs properly wired to task inputs which comes with the necessary task dependencies implicitly. In your case though it means that you are using the wrong facility. To start a server for tests and shut it down afterwards, the proper way is a shared build service. That is one of its main use-cases actually. For example how you have it now, you keep the server running and only stop it if you run libertyStop or clean which you should almost never run, because you destroy one of the biggest strengths Gradle has, avoiding unnecessary work. You also always start the server if the test task is in the task graph, even if the test task is up-to-date or getting taken from the build cache.
Regarding your actual question, you forgot to share the concrete error you are getting.
From a vague description what kind of error you see it is extremely hard to impossible to give any meaningful and helpful comment.
I think my main issue is creating the whole project structure.
My first error is duplicate content Roots detected then it goes downhill after that.
On the deployment side , I think it Open Liberty cannot find my app.jar.
I am using Intellij Idea 2025.1.3
I am trying to create an ear project:
Its contains:
app.jar (mvc)
config.jar
reportresources.jar
6 war files
All of the war java code is contained in the app.jar.
Could you share some ideas how to build this ear structure?
You showed one Gradle file of one project that is building one war file.
The content you showed should not cause duplicate content root, besides that that’s error is more an IDE topic not a Gradle topic, but it can happen if you do strange Gradle setup.
If you want to build 3 jars, 6 wars, and an ear, that would usually be 10 projects, one per artifact.
Good morning,
I converted my project to Kotlin dsl.
I cannot figure out how to create the Liberty tag properly.
I need to define bootstrap.properties because I have 2 custom definitions that
are required to load the proper server region xml and also which left Navigation to use.
Well, that’s something to complain to that plugin about.
That plugin is extremely bad implemented.
It might be halfway usable through Groovy DSL but completely fails at properly supporting Kotlin DSL,
and also does not properly work with lazy types and containers.
That plugin needs some significant refactoring work be someone that knows what they are doing.
In the meantime, you would need to cast this to the according extension classes like
liberty {
server {
this as ServerExtension
serverXmlFile = file("src/main/liberty/config/server.xml") // Example server.xml location
deploy {
this as DeployExtension
apps = listOf(tasks.ear) // Deploy the generated EAR
}
}
}