redhat-developer / redhat-developer/vscode-java
Files in .setting folder are not created properly when import gradle project
まだ誰も着手していません。
- 主要言語
- 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
- Create a gradle project by using
gradle init --type java-application - 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'
- 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
- org.eclipse.jdt.core.prefs is created with line :
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate(for-parameterscompiler argument in build.gradle) - 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 :
- 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 eclipsecommand line instead ofJava: Update project configuration
- 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 buildtask in VSCode
{
"version": "2.0.0",
"tasks": [
{
"label": "gradle clean build",
"type": "shell",
"command": "gradle clean build"
}
]
}
- Compile project with
gradle clean buildtask instead ofJava: 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Java: Update project configuration コマンドの実装と Gradle プロジェクトのインポートパスから着手し、issue の build.gradle ファイルと .settings ファイルを再現に使用します。Gradle の動作を、説明されている Maven のインポート動作と比較し、その後 org.eclipse.jdt.core.prefs と org.eclipse.core.resources.prefs が期待されるコンパイラーおよびエンコーディング設定で再作成されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java, typescript
- 領域
- build-system, tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100