The gradle java
plugin has a FileCollection
property which contains the runtime classes - sourcesets.main.runtimeClasspath
.
Is there an equivalent within the com.android.application
plugin?
compileJava — JavaCompile. Depends on: All tasks which contribute to the compilation classpath, including jar tasks from projects that are on the classpath via project dependencies. Compiles production Java source files using the JDK compiler. processResources — ProcessResources.
implementation configuration is used for compile and runtime classpath but it is only exposed to the consumers for their runtime classpath. runtimeOnly configuration is only used for the runtime classpath and it is also exposed to the consumers for their runtime classpath.
The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.
What I've found is that the destinationDir
property of applicationVariants
can be appended to the javaCompile.classpath
property, which will result in a FileCollection
which contains the dependency classpaths and the compiled classes.
My use case is trying to run a java executable post-compile:
afterEvaluate {
android.applicationVariants.each { variant ->
variant.javaCompile.doLast {
javaexec {
classpath += variant.javaCompile.classpath
classpath += files(variant.javaCompile.destinationDir)
main = 'com.mydomain.Main'
}
}
}
}
Tested on Android Studio 2.1.1 running 'com.android.tools.build:gradle:2.1.0'
and gradle 2.10.
Reference: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Shrinking-Resources
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With