Adam
Adam

Reputation: 862

Adding source files to Gradle project

Let's assume I've got a simple Android project which I'm gonna build by Gradle.

Is it possible to add sources from arbitrary directory?

So I'd like to keep main sourceSets intact, just to add some java-files which are located in path to sources.

Upvotes: 4

Views: 3274

Answers (2)

Jon
Jon

Reputation: 9803

Here's what I did to finally do this. In my case I wanted to have some common java source files for a couple different build flavors.

sourceSets {
    favorA1 {
        java {
            srcDirs('src/favorA1/java/src', 'src/commonA/java/src')
        }
    }
    favorA2 {
        java {
            srcDirs('src/favorA2/java/src', 'src/commonA/java/src')
        }
    }
}

If you just want to add a source directory to all of your build variants, try something like the following:

sourceSets {
    main{
        java {
            srcDirs('src/main/java/src', 'src/additionalCode/java/src', '../other/sources')
        }
    }
}

Gradle Java
Gradle Source Api

Upvotes: 0

The End
The End

Reputation: 709

Just add the folder to java.srcDir. It is just a Set of Files, so you can add more Files like any other Set in groovy.

One example to do so is to add this snippet:

sourceSets {
    main{
        java {
            srcDir("path/to/source/folder")
        }
    }
}

Upvotes: 3

Related Questions