gpt4 book ai didi

java - Eclipse Spring Boot 构建路径包含重复条目

转载 作者:行者123 更新时间:2023-11-30 07:16:07 25 4
gpt4 key购买 nike

我对 this one 有完全相同的问题。不幸的是他也没有找到最终的一次性修复解决方案。

每次创建新项目或使用 gradle 刷新依赖项时,我都会遇到构建路径包含重复条目错误(maven 工作正常,但 gradle 不行)。

每次构建后我都必须手动删除额外的 jre 系统库。我认为这个问题可能是由gradle设置引起的。因为在我手动修复问题后,如果我刷新 gradle 依赖项,它会再次出现。

这里是默认的 sts build.gradle 模板。

buildscript {
ext {
springBootVersion = '1.3.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'

war {
baseName = 'demo'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
}

configurations {
providedRuntime
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}

eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}

从.classpath文件中可以看到,jreSE-1.8有2个相同的classpathentry

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry sourcepath="C:/Users/leo.zhou/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-jdbc/1.3.6.RELEASE/8b780842222e055a165198d9f8198d3ff0da7f05/spring-boot-starter-jdbc-1.3.6.RELEASE-sources.jar" kind="lib" path="C:/Users/leo.zhou/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-starter-jdbc/1.3.6.RELEASE/6a1bd13afbae1dcd7207dfd6f8fd94b549fa32e5/spring-boot-starter-jdbc-1.3.6.RELEASE.jar">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry> .....

请提供任何帮助,我们将不胜感激。

最佳答案

尝试将以下内容添加到构建脚本的依赖项

classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")

apply plugin: 'io.spring.dependency-management' 

task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}

位于 build.gradle 文件的末尾。

关于java - Eclipse Spring Boot 构建路径包含重复条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38383707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com