0

Basically, I'm using an open-source library in my main project. The library is included by compile project('<path-to-lib>'). The trouble is, there're a lot of files/classes/resources which I don't really need. I only need a small subset of those. Instead of deleting redundant parts, is there any way for me to write Groovy/Gradle script to pick only essential parts for building? This way, ideally, I can make minimal changes to the library.

Thuy Trinh
  • 2,914
  • 1
  • 22
  • 35
  • You could fork the project and adapt its build, or you add some logic to your build to repackage the artifact(s) that the project dependency gets resolved to. – Peter Niederwieser Mar 04 '14 at 17:15

1 Answers1

0

In the build file for the library you can tailor the source sets to your needs. In general you write something like this:

apply plugin: 'java'

sourceSets {
  main {
    java {
      exclude 'some/unwanted/package/**'
    }
  }
}

I'm assuming this is a plain Java library. If it's an Android library, the android-library plugin also supports exclude syntax in source sets.

Here's a SO question for reference:

Android Studio Exclude Class from build?

You can also read the Gradle docs for source sets at http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.SourceSet.html#org.gradle.api.tasks.SourceSet:java(groovy.lang.Closure) and the Java plugin at http://www.gradle.org/docs/current/userguide/java_plugin.html

Community
  • 1
  • 1
Scott Barta
  • 79,344
  • 24
  • 180
  • 163