简体   繁体   中英

Gradle/Android - Select essential files to build

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM