2016-12-20 5 views
0

私はJava(EJBプロジェクト)とEclipseの動的WebプロジェクトをGradleに移行しています。私はBuildshipを使用しています。私のプロジェクトにはEclipseライブラリの設定があります。これは維持するのが苦痛でした。グレードは、build.gradleファイルにこれらの "依存関係"を追加するだけで十分です。あなたは知っています。それはいいです。Eclipse Buildship(Gradle Plugin)は、依存関係に基づいてJavaプロジェクトライブラリのパス設定を更新できますか?

私の質問は、EclipseのプラグインをGradleで使用して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' 

} 
+0

ビルドシップはすでにそれを実行している必要があります、それは既存の理由の一部です。あなたの '.project'と' .classpath'ファイルの内容を表示するために質問を編集してください。 –

+0

ありがとうございます。私はそれらを追加しました。 Gradle Tasksでビルドを実行すると、ライブラリとクラスのパスが変更されますか?私はプラグインが.classpathのソースを更新したが、jarとライブラリのエントリは更新していないのを見た。 – icordoba

+0

OK、問題とプラグインのドキュメントについて読んで、シェルを開いて "gradle eclipseClasspath"を実行すると、.classpathが更新されることがわかりました。なぜ私はGradle Tasksビューでそのタスクが表示されないのだろうかと思います。 (私は明らかにGradleを初めて使っています) – icordoba

答えて

0

私はあなたが必要だと思う、または必要にありませんGradleのeclipseClasspathタスクを使用してください。 Buildshipは正しいプロジェクト構成を維持する必要があります。

問題は、プロジェクトのビルドパスに手作業で追加されたライブラリが残っていることです。たとえば、ジャクソン、コモンズコレクション、レディスなどは除外し、図書館が残っているのは「プロジェクトと外部の依存関係」だけです。あなたのプロジェクトのビルド・パスのライブラリは、基本的に次のようになります。

enter image description here

は、コモンズのコレクションやSLF4Jとして、プロジェクトの下でbuild.gradleファイルから、それはいくつかのライブラリが含まれてどのように参照および外部依存?

ビルドパスを設定して、Gradleに変更を依頼するのではなく、Eclipse-project設定を更新/管理することができます。build.gradleに変更した後、プロジェクトを右クリックし、Gradle>更新Gradleのプロジェクト

Bulidshipが自動的build.gradleが変更されました。このすべての時間を行うためのオプションを持っていた場合、それはいいだろうが、私は問題になる可能性がありますそうすることのパフォーマンスを疑います。

+0

OK。説明ありがとう。私はそれがすでに働いていたが、ビルドシップがライブラリのそのプロジェクトと外部依存関係エントリを更新しているかどうかはわかりませんでした。私はライブラリを削除し、EclipseはプロジェクトをOKにコンパイルします。 – icordoba

関連する問題