question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
Environment
  • Operating System: Linux 3.10.0-957.21.3.el7.x86_64 #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™ 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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rubensacommented, 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/")
        }
      }
    }
  }
}
0reactions
nqminhuitcommented, Dec 11, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Studio: Resolving Duplicate Classes - gradle
Sometimes duplicate classes exception means that one of your dependencies uses ... that AGP gets both build/classes/java/main and build/libs/lib.jar (run .
Read more >
How to avoid duplicate classes for build types ?
My idea is to redefine some classes and layouts in the admin folder, in order to add special capabilities. But when I launch...
Read more >
Shrink, obfuscate, and optimize your app
Learn how to shrink code in your release build to remove unused code and resources.
Read more >
Maven and Gradle support for Java in Visual Studio Code
The extension provides a visual interface for your Gradle build, you can use this interface to view Gradle Tasks and Project dependencies, or...
Read more >
Upgrading your build from Gradle 5.x to 6.0
The usage of the compile and runtime configurations in the Java ecosystem ... this from happening accidentally, encountering duplicates while creating an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found