我正在尝试用一些API端点构建一个spring应用程序。每次我尝试运行"gradle build“时,都会出错:
Entry META-INF/MANIFEST.MF is a duplicate but no duplicate handling strategy has been set.
以下是生成扫描的输出:
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.
build.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()
}
到目前为止我尝试过的解决方案:
发布于 2022-11-23 23:51:56
可以通过将其添加到build.gradle中来解决这一问题:
tasks.withType(Jar) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes["Main-Class"] = "com.example.backendapp.BackendAppApplication"
}
}
https://stackoverflow.com/questions/74554033
复制相似问题