4

I am trying to migrate my android library project from ant to gradle and I am totally stuck with including project dependencies in final jar + excluding some other resources (mostly android auto generated classes like BuildConfig, etc) from it.

My ant jar task looks like this:

<jar destfile="${dist}/lib/LIB_NAME.jar"
     basedir="${build.dir}/classes"
     includes="com/**"
     excludes="**/R.class, **/R$*.class, **/Manifest*.class">

     <manifest>
      <attribute name="Main-Class" value="PACKAGE"/>
     </manifest>
</jar>

I would like to reach similar effect using gradle + include subset of dependencies in final jar. My current approach is based on Jake Wharton solution, which does not bundle dependencies:

android.libraryVariants.all { variant ->
    def name = variant.buildType.name
    if (name.equals(com.android.builder.BuilderConstants.DEBUG)) {
        return; // Skip debug builds.
    }
    def task = project.tasks.create "jar${name.capitalize()}", Jar
    task.dependsOn variant.javaCompile
    task.from variant.javaCompile.destinationDir
    artifacts.add('archives', task);
}

Any easy solutions how to modify it to include dependencies + exclude other content? Or maybe there is some more standard way of achieving my goals - I expected it more easy in gradle.

Community
  • 1
  • 1
mkorszun
  • 4,461
  • 6
  • 28
  • 43

0 Answers0