First, why your approach does not work:
apply from:
applies a gradle script to a project object. This means you can configure the project in the script, but a local method defined in that script will not magically be available in a different script.
What you CAN do is set your method as an extension property on the project object. Then your method will become available to other scripts via the project object.
change /common-deps.gradle to
ext.addHttpComponents = {
dependencies {
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.1'
}
}
and things should work better.
Next, your approach seems a bit convoluted to me anyway. Why not just:
common-deps.gradle
dependencies {
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.1'
}
and then in /sub-project/build.gradle
apply from: rootProject.file('common-deps.gradle')
Lastly, I think you mean
apply plugin: 'maven'
apply plugin: 'java'
in /sub-project/build.gradle