gradle打包Android程序,如何打包时不包含依赖包

使用gradle打包Android程序,希望不包含依赖的lib中的jar包,就像在eclipse的build Path中勾掉依赖,同理下图的操作怎么在gradle的构建打包中实现

Eclipse这样

https://stackoverflow.com/questions/16107477/gradle-how-to-make-a-compile-scope-file-dependency-excluded-in-packaging

There probably is a cleaner and simpler solution but you could then specify a custom configuration:

configurations {
compileOnly
}
and then specify all dependencies:

dependencies {
compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compileOnly files('dependencies/compile/archive/management.jar')
}
Finally add the compileOnly configuration to classpaths of all source sets

sourceSets.all {
compileClasspath += configurations.compileOnly
}
This way management.jar should be on the classpath for compilation but won't be packaged.

EDIT Only now I fully understand your problem. The following worked for me on a test project.

In core project gradle file:

repositories {
flatDir {
dirs 'dependencies/compile/archive'
}
}

dependencies {
compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')
compile ':management:'
}
In project that depends on core:

repositories {
flatDir {
dirs new File(project(':core').projectDir, 'dependencies/compile/archive')
}
}

dependencies {
compile(project(':core')) {
exclude module: 'management'
}
compileOnly ':management':
}

sourceSets.all {
compileClasspath += configurations.compileOnly
}