redhat-developer / redhat-developer/vscode-java

Files in .setting folder are not created properly when import gradle project

オープン
#666 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Gradle
主要言語
TypeScript
スター
2.3k
フォーク
546
平均マージ
20時間 1分
マージ済み PR(30日)
11

説明

When import a gradle project, org.eclipse.* files in .setting folder are not created enough base on build.gradle file. Only org.eclipse.buildship.core.prefs is created, and if I deleted that file, it can not be re-created by run Java: update project configuration command unless I clear workspaceStorage.

Environment
  • Operating System: windows 10 pro version 1803 build 17134.228
  • JDK version:
    >java --version
    java 10.0.2 2018-07-17
    Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
    Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
  • Visual Studio Code version: 1.27.2 (user setup)
  • Java extension version: 0.32.0
Steps To Reproduce
  1. Create a gradle project by using gradle init --type java-application
  2. Add these lines in build.gradle file
compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs << '-parameters'
compileTestJava.options.encoding = 'UTF-8'
compileTestJava.options.compilerArgs << '-parameters'
  1. Open project folder using VSCode and wait for it import the project

sample project :
gradleinit.zip

logs:
first-time-import-project.log
run-java-update-project-configuration-command.log

Current Result

Only org.eclipse.buildship.core.prefs is created

Expected Result
  1. org.eclipse.jdt.core.prefs is created with line :
    org.eclipse.jdt.core.compiler.codegen.methodParameters=generate (for -parameters compiler argument in build.gradle)
  2. org.eclipse.core.resources.prefs is created with lines :
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8

These two files are created fine when I import a maven project with identical option in pom.xml

Workarounds :
  1. Option 1: Use gradle eclipse plugin
  • Add these lines to build.gradle
plugins {
  id 'java'
  id 'application'
  id 'eclipse'
}

def DEFAULT_ENCODE = 'UTF-8'
eclipse {
  jdt {
    sourceCompatibility = 1.10
    targetCompatibility = 1.10

    file {
      withProperties { properties ->
        properties.'org.eclipse.jdt.core.compiler.codegen.methodParameters' = 'generate'
      }
    }
  }
}

eclipseJdt {
  doLast {
    file('.settings/org.eclipse.core.resources.prefs').withWriter { writer ->
      def engine = new groovy.text.SimpleTemplateEngine()
      def contents = '''\
          |eclipse.preferences.version=1
          |encoding//src/main/java=${encode}
          |encoding//src/test/java=${encode}
          |encoding/<project>=$encode
          |'''

      def data = ['encode': DEFAULT_ENCODE]
      contents = engine.createTemplate(contents).make(data).toString()
      writer << contents.stripMargin()
    }
  }
}
  • Use gradle eclipse command line instead of Java: Update project configuration
  1. Option 2: Give up Jdt compiler a.k.a don't care about .setting folder
  • Disable auto compile : "java.configuration.updateBuildConfiguration": "disabled"
  • Add these lines to build.gradle:
task cleanFiles(type: Delete) {
  delete 'bin/main', 'bin/test'
}

task copySource(type: Copy) {
  from 'build/classes/java/main'
  from 'build/resources/main'
  into 'bin/main'
}

task copyTest(type: Copy) {
  from 'build/classes/java/test'
  from 'build/resources/test'
  into 'bin/test'
}


task runAfterBuild(type: Copy) {
  dependsOn 'copySource'
  dependsOn 'copyTest'
}

build.finalizedBy(runAfterBuild)
  • Add gradle clean build task in VSCode
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "gradle clean build",
      "type": "shell",
      "command": "gradle clean build"
    }
  ]
}
  • Compile project with gradle clean build task instead of Java: Force Java Compilation. Every time gradle finish build task, it will copy compiled code to bin folder for debugging. You can add "preLaunchTask": "gradle clean build" to launch.json to auto run gradle build every time you start debugging.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Java: Update project configuration コマンドの実装と Gradle プロジェクトのインポートパスから着手し、issue の build.gradle ファイルと .settings ファイルを再現に使用します。Gradle の動作を、説明されている Maven のインポート動作と比較し、その後 org.eclipse.jdt.core.prefsorg.eclipse.core.resources.prefs が期待されるコンパイラーおよびエンコーディング設定で再作成されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java, typescript
領域
build-system, tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。