Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS code java creates duplicate classes in Java project with Gradle build #1187

Closed
nqminhuit opened this issue Dec 10, 2019 · 5 comments
Closed
Labels

Comments

@nqminhuit
Copy link

nqminhuit commented Dec 10, 2019

Environment
  • Operating System: Linux 3.10.0-957.21.3.el7.x86_64 release to marketplace #1 SMP Fri Jun 14 02:54:29 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux
  • JDK version: 1.8.0_151
  • Visual Studio Code version: 1.40.2
  • Java extension version: 0.54.2
  • Gradle version: 6.0.1
Steps To Reproduce
  1. Create a default Java application with Gradle:
$ mkdir java-simple-app
$ cd java-simple-app/
$ gradle init

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 2

Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Swift
Enter selection (default: Java) [1..5]

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2]

Select test framework:
  1: JUnit 4
  2: TestNG
  3: Spock
  4: JUnit Jupiter
Enter selection (default: JUnit 4) [1..4]

Project name (default: java-simple-app):
Source package (default: java.simple.app): org.my.app

> Task :init
Get more help with your project: https://docs.gradle.org/6.0.1/userguide/tutorial_java_projects.html

BUILD SUCCESSFUL in 37s
2 actionable tasks: 2 executed
  1. Open the newly created project with vscode, wait for "Language Support for Java(TM) by Red Hat" extension to initialize project
  2. Check the project folder tree:
java-simple-app/
|-- bin
|   |-- main
|   |   `-- org
|   |       `-- my
|   |           `-- app
|   |               `-- App.class
|   `-- test
|       `-- org
|           `-- my
|               `-- app
|                   `-- AppTest.class
|-- build
|   |-- classes
|   |   `-- java
|   |       |-- main
|   |       |   `-- org
|   |       |       `-- my
|   |       |           `-- app
|   |       |               `-- App.class
|   |       `-- test
|   |           `-- org
|   |               `-- my
|   |                   `-- app
|   |                       `-- AppTest.class
|   |-- generated
|   |   `-- sources
|   |       `-- annotationProcessor
|   |           `-- java
|   |               |-- main
|   |               `-- test
|   |-- reports
|   |   `-- tests
|   |       `-- test
|   |           |-- classes
|   |           |   `-- org.my.app.AppTest.html
|   |           |-- css
|   |           |   |-- base-style.css
|   |           |   `-- style.css
|   |           |-- index.html
|   |           |-- js
|   |           |   `-- report.js
|   |           `-- packages
|   |               `-- org.my.app.html
|   |-- test-results
|   |   `-- test
|   |       |-- binary
|   |       |   |-- output.bin
|   |       |   |-- output.bin.idx
|   |       |   `-- results.bin
|   |       `-- TEST-org.my.app.AppTest.xml
|   `-- tmp
|       |-- compileJava
|       `-- compileTestJava
|-- build.gradle
|-- gradle
|   `-- wrapper
|       |-- gradle-wrapper.jar
|       `-- gradle-wrapper.properties
|-- gradlew
|-- gradlew.bat
|-- settings.gradle
`-- src
    |-- main
    |   |-- java
    |   |   `-- org
    |   |       `-- my
    |   |           `-- app
    |   |               `-- App.java
    |   `-- resources
    `-- test
        |-- java
        |   `-- org
        |       `-- my
        |           `-- app
        |               `-- AppTest.java
        `-- resources

54 directories, 23 files
Question

The 'build' dir is from Gradle build task and its content looks similar to the 'bin' dir, which is generated by the extension. What is this 'bin' dir for?

@fbricon
Copy link
Collaborator

fbricon commented Dec 10, 2019

Gradle support is provided by the Buildship project. Separating the output directories of Eclipse and CLI builds is a design decision, basically to prevent conflicts between IDE and CLI builds. More about here: https://discuss.gradle.org/t/eclipse-plugin-did-not-configure-default-output-directory-to-build/7586.

@fbricon fbricon added the Gradle label Dec 10, 2019
@nqminhuit
Copy link
Author

Thank Fred for your reply.

So they are separated as designed. That makes sense when we usually encounter the problem with new dependencies added in gradle build script, the build from CLI is working, but vscode shows error that symbols not found until we reload the vscode again. Is there a way to sync new dependencies from gradle without reloading the whole workspace?

@snjeza
Copy link
Contributor

snjeza commented Dec 11, 2019

You can try the following:

  • open build.gradle
  • right click and run Update Project Configuration

You can also try the following property:

 "java.configuration.updateBuildConfiguration": "automatic"

@nqminhuit
Copy link
Author

@snjeza perfect! This is what we needed, thank you very much!

@rubensa
Copy link

rubensa commented Jan 22, 2020

I ended with this configuration in my build.gradle so gradle build on "build/gradle" and eclipse on "build/eclipse":

buildDir = "build/gradle"
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
  classpath {
    defaultOutputDir = file('build/eclipse')
    file.whenMerged {
      entries.each { entry ->
        if (entry.kind == 'src' && entry.hasProperty('output')) {
          entry.output = entry.output.replace('bin/', "build/eclipse/")
        }
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants