如何使用Gradle构建WildFly可执行Jar?官方文档仅提供Maven插件方案的替代方法问询
Great question! Let’s clear this up for you:
WildFly’s official documentation only covers using the wildfly-jar-maven-plugin for building bootable Jars, and there’s no official Gradle plugin equivalent available right now.
That said, the workaround you referenced is indeed the closest practical solution we have at the moment—here’s a more detailed breakdown of how to implement it:
Step 1: Build a WildFly Hollow Bootable Jar with Maven
A Hollow Jar is a lightweight, reusable WildFly runtime that doesn’t include your application code. Set up a simple Maven project, add thewildfly-jar-maven-plugin, configure it to use thehollowgoal, and build the Jar. Publish it to your local Maven repository (or a private repo) so your Gradle project can pull it in as a dependency.Step 2: Integrate the Hollow Jar into your Gradle WAR project
Add the published Hollow Jar as a dependency in your Gradle build file. Then create a custom task to launch the WildFly runtime, pointing it to your compiled WAR file. For example, abootRuntask using JavaExec would look something like this:
task bootRun(type: JavaExec) { mainClass = 'org.wildfly.jar.boot.Main' classpath = sourceSets.main.runtimeClasspath args = ['--deploy', "${buildDir}/libs/your-application.war"] }
A quick note: Some community members have experimented with wrapping the Maven plugin’s logic in Gradle (using tools like the Gradle Maven plugin or custom tasks), but these are unofficial solutions and may lack the same level of support or updates as the official Maven tooling.
内容的提问来源于stack exchange,提问作者bollin

