简体   繁体   English

Gradle / Android-选择要构建的基本文件

[英]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>') . 该库包含在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? 除了删除多余的零件,我还有什么办法编写Groovy / Gradle脚本以仅选择构建所需的零件? 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. 我假设这是一个普通的Java库。 If it's an Android library, the android-library plugin also supports exclude syntax in source sets. 如果是Android库,则android-library插件还支持源集中的exclude语法。

Here's a SO question for reference: 这是一个SO问题供参考:

Android Studio Exclude Class from build? Android Studio是否从类中排除类?

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 您还可以在http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.SourceSet.html#org.gradle.api.tasks.SourceSet:java中阅读Gradle文档以获取源集。 (groovy.lang.Closure)和Java插件, 网址http://www.gradle.org/docs/current/userguide/java_plugin.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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