首页 文章

Eclipse Buildship(Gradle插件)可以根据它的依赖关系更新我的java项目库路径配置吗?

提问于
浏览
0

我正在将Eclipse中的Java(EJB项目)和Dynamic Web项目迁移到Gradle . 我正在使用Buildship . 我的项目有一个Eclipse Library配置,维护起来很痛苦 . 这个很好,因为我只是将这些“依赖”添加到build.gradle文件......等等 . 你知道 . 没关系 .

我的问题是,如果我可以使用Gradle中的Eclipse插件使其在eclipse中重新配置项目的Build路径并删除旧的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'

}

1 回答

  • 0

    我认为您不需要或不想在Gradle中使用 eclipseClasspath 任务 . Buildship应该为您维护正确的项目配置 .

    问题是您仍然在项目构建路径中手动添加了库 . 例如,Jackson,Commons Collections,Redis等 . 这些应该被删除,只剩下Gradle管理的“ Project and External Dependencies ”库 . 您的项目的构建路径库应该基本上如下所示:

    enter image description here

    看看它如何包含 Project and External Dependencies 下的 build.gradle 文件中的一些库,例如commons集合和slf4j?

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

    如果Bulidship有一个选项可以随时自动执行此操作 build.gradle 会更好,但我怀疑这样做的表现可能是一个问题 .

相关问题