Build Types (debug, release, or custom) can have their own dependencies.
To specify a dependency specific to a build type, do the following:
dependencies {
debugCompile "mydebugdependency"
releaseCompile "myreleasedependency"
}
If your java project and android project are both using gradle, you can do the above in both of their build.gradle files.