条目 META-INF/MANIFEST.MF 重复,但未设置重复处理策略

Ruc*_*ore 3 java gradle build.gradle

我正在尝试使用一些 API 端点构建一个 Spring Web 应用程序。每次我尝试运行“gradle build”时,都会出现错误:

Entry META-INF/MANIFEST.MF is a duplicate but no duplicate handling strategy has been set.
Run Code Online (Sandbox Code Playgroud)

以下是 build --scan 的输出:

3:23:01 pm: Executing 'build --scan'...

> Task :compileJava
> Task :processResources UP-TO-DATE
> Task :classes
> Task :bootJarMainClassName
> Task :bootJar FAILED
4 actionable tasks: 3 executed, 1 up-to-date

Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https://gradle.com/terms-of-service. Do you accept these terms? [yes, no] 
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootJar'.
> Entry META-INF/MANIFEST.MF is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.2/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.
Run Code Online (Sandbox Code Playgroud)

构建.gradle:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.5'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
        attributes(
                'Main-Class': 'com.example.backendapp.BackendAppApplication'
        )
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过的解决方案:

  1. 在 jar 内添加“duplicatesStrategy = DuplicatesStrategy.EXCLUDE”
  2. 将 gradle 版本从 7.5.1 降级到 7.2

Ruc*_*ore 6

这可以通过将其添加到 build.gradle 来解决:

tasks.withType(Jar) {
   duplicatesStrategy = DuplicatesStrategy.EXCLUDE

   manifest {
      attributes["Main-Class"] = "com.example.backendapp.BackendAppApplication"
   }
}
Run Code Online (Sandbox Code Playgroud)