You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Gradle Script Kotlin中配置Spring Boot 2 Gradle插件禁用Boot分发

Create an Assembly Bundle with Dependencies in 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.main block—for example, add more from entries or rename the output with tasks.distZip.archiveFileName.set("custom-bundle-name.zip").

内容的提问来源于stack exchange,提问作者bjartek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:38:00