eclipse - Eclipse Buildship(Gradle插件)能否基于其依赖项来更新我的Java项目库路径配置?

标签 eclipse gradle buildship

我正在将Eclipse中的Java(EJB项目)和Dynamic Web项目迁移到Gradle。我正在使用Buildship。我的项目具有Eclipse库配置,很难维护。有了等级,这很棒,因为我只是将那些“依赖项”添加到build.gradle文件中...等等。您知道。没关系。

我的问题是我是否可以在Gradle中使用Eclipse插件使其重新配置eclipse中项目的构建路径并删除旧的Eclipse库,并让Eclipse中的项目基于Gradle下载的 jar 作为依赖项进行构建,所以如果我更改其中一个依赖项的版本后,Eclipse编译器还将基于该新的jar依赖项编译代码。谢谢。

我编辑添加文件:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>ElizaTourismEJB</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.eclipse.wst.common.project.facet.core.builder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.jboss.tools.jst.web.kb.kbbuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.jboss.tools.cdi.core.cdibuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.eclipse.wst.validation.validationbuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.hibernate.eclipse.console.hibernateBuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>
                <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
                <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
                <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
                <nature>org.eclipse.jdt.core.javanature</nature>
                <nature>org.jboss.tools.jst.web.kb.kbnature</nature>
                <nature>org.jboss.tools.cdi.core.cdinature</nature>
                <nature>org.hibernate.eclipse.console.hibernateNature</nature>
                <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
        </natures>
</projectDescription>

.classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="src" path="src/main/java">
                <attributes>
                        <attribute name="FROM_GRADLE_MODEL" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" path="src/test/java">
                <attributes>
                        <attribute name="FROM_GRADLE_MODEL" value="true"/>
                </attributes>
        </classpathentry>
        <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.buildship.core.gradleclasspathcontainer">
                <attributes>
                        <attribute name="org.eclipse.jst.component.nondependency" value=""/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
        <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Jackson2"/>
        <classpathentry kind="lib" path="commons-collections4-4.1.jar"/>
        <classpathentry kind="lib" path="/ElizaTourismREST/WebContent/WEB-INF/lib/freemarker.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Redis"/>
        <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.ibm.ws.st.core.runtimeClasspathProvider/WebSphere Application Server Liberty Profile 16003">
                <attributes>
                        <attribute name="owner.project.facets" value="jst.ejb;jpt.jpa"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="lib" path="/Developer/java-lib/aspirin-0.11.01.jar"/>
        <classpathentry kind="src" path=".apt_generated">
                <attributes>
                        <attribute name="optional" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="output" path="target/bin"/>
</classpath>

build.gradle:
apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    jcenter()
    mavenCentral()
}

ext {
    swagger_annotations_version = "1.5.9"
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.21'

    testCompile 'junit:junit:4.12'

    compile group: 'javax', name: 'javaee-api', version:'7.0'
    compile "io.swagger:swagger-annotations:$swagger_annotations_version"
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.5.4'
    compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-jaxb-annotations', version: '2.5.4'
    compile group: 'biz.paluch.redis', name: 'lettuce', version: '4.3.0.Final'
    compile group: 'org.masukomi', name: 'aspirin', version: '0.11.01'
    compile group: 'org.freemarker', name: 'freemarker', version: '2.3.23'

}

最佳答案

我认为您不需要或不想在Gradle中使用eclipseClasspath任务。造船厂应为您维护正确的项目配置。

问题是您仍在项目“构建路径”中手动添加了库。例如, jackson (Jackson),下议院收藏(Commons Collections),雷迪斯(Redis)等。这些应该被删除,仅保留Gradle管理的“项目和外部依赖项”库。您项目的构建路径库基本上应如下所示:

enter image description here

看看它如何包含项目和外部依赖项build.gradle文件中的一些库,例如commons集合和slf4j?

通过这种方式设置构建路径,您可以让Buildship更新/管理Eclipse项目设置,而不是要求Gradle进行此操作:对build.gradle进行更改后,右键单击该项目,然后选择 Gradle > 刷新Gradle项目

如果Bulidship可以选择在build.gradle更改时自动执行此操作,那就太好了,但是我怀疑这样做的性能可能会成为问题。

关于eclipse - Eclipse Buildship(Gradle插件)能否基于其依赖项来更新我的Java项目库路径配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41245795/

相关文章:

java - gradle 上构建错误 : cannot find symbol

eclipse - 如何在导入项目时将参数传递给eclipse Buildship插件中的gradle

eclipse - Gradle Build配置帮助-Eclipse Oxygen

java - Eclipse错误: Could not find or load main class opencv

java - 无法加载 Tomcat 服务器配置

android - Import vs Gradle实现…什么时候使用?

gradle - 如何在现有Gradle项目中使用Buildship

eclipse - 将 GWT 2.0.4 项目迁移到 GWT 2.1.0

java - 简单计算器应用程序中的资源$NotFoundException

spring-boot - 从 springBoots `bootJar` gradle 任务中排除特定依赖项