redhat-developer / redhat-developer/vscode-java

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

Open
#666 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Gradle
Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the implementation behind the Java: Update project configuration command and the Gradle project import path, using the issue's build.gradle and .settings files as the reproduction. Compare the Gradle behavior with the Maven import behavior described, then verify that org.eclipse.jdt.core.prefs and org.eclipse.core.resources.prefs are recreated with the expected compiler and encoding settings.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.