如何在Gradle Script Kotlin中配置Spring Boot 2 Gradle插件禁用Boot分发
lib Using Aurora Skatteetaten Gradle Plugin Alright, since you’re already set up with the jar task enabled and bootJar disabled, let’s leverage the Aurora Skatteetaten Gradle plugin’s built-in distribution features to build your assembly bundle with all dependencies tucked neatly into a lib directory. Here’s a straightforward step-by-step configuration:
1. Configure the Distribution Setup
The Aurora plugin integrates seamlessly with Gradle’s core distribution plugin, so we’ll extend the default distribution to include your compiled JAR and all runtime dependencies in the lib folder. Add this to your build.gradle.kts:
// Ensure the Aurora Java plugin is applied (adjust based on your module type) plugins { id("no.skatteetaten.aurora.java") version "<your-plugin-version>" } distributions { main { contents { // Place your compiled JAR at the root of the bundle from(tasks.jar) // Copy all runtime dependencies into the `lib` subdirectory from(configurations.runtimeClasspath) { into("lib") } // Optional: Add configuration files or additional resources if needed from("src/main/resources") { into("config") } } } } // Optional: Tie bundle generation to the standard `assemble` task tasks.assemble { dependsOn(tasks.distZip, tasks.distTar) }
2. Finalize the JAR Manifest (For Applications)
Since you’re using the standard jar task instead of bootJar, make sure your JAR has a valid manifest pointing to your main class (if this is a runnable application):
tasks.jar { manifest { attributes["Main-Class"] = "com.yourpackage.YourMainClass" // Optional: Add a classpath attribute to reference JARs in the `lib` directory attributes["Class-Path"] = configurations.runtimeClasspath.files.joinToString(" ") { "lib/${it.name}" } } }
3. Generate the Assembly Bundle
Run this command to build your compressed bundle:
./gradlew assemble
You’ll find the finished ZIP and TAR bundles in the build/distributions directory. When extracted, the structure will look like this:
your-app-bundle/ ├── your-app.jar ├── lib/ │ ├── dependency-1.jar │ ├── dependency-2.jar │ └── ... (all runtime dependencies) └── config/ (optional, if you included resources) └── application.properties
Quick Notes
- The Aurora plugin handles dependency resolution automatically, so you don’t need to manually copy or manage JAR files.
- If you want a custom bundle name or extra files, tweak the
distributions.mainblock—for example, add morefromentries or rename the output withtasks.distZip.archiveFileName.set("custom-bundle-name.zip").
内容的提问来源于stack exchange,提问作者bjartek

