问题描述
- gradle打包Android程序,如何打包时不包含依赖包
- 使用gradle打包Android程序,希望不包含依赖的lib中的jar包,就像在eclipse的build Path中勾掉依赖,同理下图的操作怎么在gradle的构建打包中实现
解决方案
解决方案二:
楼主有啥解决思路吗?
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
}