Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Gradle default Source Sets

I'm trying to run gradle to generate an eclipse project.

I'd like the following structure:

project
└── src 
    ├── main 
    │   ├── ...
    │   ├── ...
    │   └── ...
    └── test 
        ├── ...
        ├── ...
        └── ...

Here is the relevant part of my build.gradle:

sourceSets {
    main {
        java {
            srcDir 'main'
        }
    }
    test {
        resources {
            srcDir 'test'
        }
    }
}

It generates this .classpath:

    <classpathentry kind="src" path="src/main"/>
    <classpathentry kind="src" path="src/test"/>
    ...
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/test/java"/>

This seems to be confusing eclipse. I'd like to remove the default source sets in gradle (I think that's the solution) which will generate a proper .classpath.

like image 363
cdosborn Avatar asked Jan 27 '16 03:01

cdosborn


2 Answers

As per SourceDirectorySet documentation here

srcDir adds a new location to the set, while setSrcDirs replaces, and is likely what you're looking for.

like image 162
RaGe Avatar answered Oct 29 '22 11:10

RaGe


Try

sourceSets { 
  main { 
    java { srcDirs = [ 'main' ] } 
  }
  test { 
    java { srcDirs = [ 'test' ] } 
  }
}

This overrides the source set property, instead of extending it. You can add more comma-separated directories in square brackets.

like image 42
Andrzej Wąsowski Avatar answered Oct 29 '22 12:10

Andrzej Wąsowski