8

I have following 2 projects placed adjacent to each other in some folder and I want to include specific sources from a non-gradle project into this project with the structure as follows.

rootfolder/
  my-gradle-project/
    src/main/java
    build.gradle

  my-non-gradle-project/
    src/main/java/com/example/utils

In build.gradle why would following not work ? What alternative do I have ?

Additionally I need to included specific java sources from the non-gradle project.

build.gradle

sourceSets.main.java.srcDirs = [
          'src/main/java', 
           '../my-non-gradle-project/src/main/java/com/example/util')]
bhantol
  • 9,368
  • 7
  • 44
  • 81
  • Found out that it actually works fine except that the package is all messed up. Sources in `com/example/util` appear as in default package. So this now boils down to the other half of the problem which is - how to include specific sources without the package mess. – bhantol Dec 16 '16 at 19:05
  • use `'../my-non-gradle-project/src/main/java'` as your second path? – RaGe Dec 19 '16 at 15:23
  • The problem with `src/main/java` is it will include all the sources. I want only specific path. This is an odd project that I don;t have control otherwise lot more could have been done. – bhantol Dec 19 '16 at 15:25
  • 1
    To get the package right, you *have* to use the `src` path. Looks like SourceDirectorySet takes includes and excludes filters https://docs.gradle.org/current/javadoc/org/gradle/api/file/SourceDirectorySet.html. Filters may apply to both your paths though, which you may be able to circumvent using separate sourceSets. – RaGe Dec 19 '16 at 15:47
  • Separate sourceSets seems like a best option. – bhantol Dec 19 '16 at 16:01

1 Answers1

2

The following worked in intelliJ:

...
group 'org.example'
version '1.0-SNAPSHOT'

sourceSets {
    main {
        java{
            srcDirs '../my-non-gradle-project/src/main/java/com/example/util' /* include proto files from base project level */
        }
    }
}

sourceCompatibility = 1.11
...
Dávid Tóth
  • 2,788
  • 1
  • 21
  • 46