build.gradle revision d437f7eeb199ed9bf9fb9bed664258dbbcd87130
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import com.android.build.transform.api.QualifiedContent;
17import com.android.build.transform.api.QualifiedContent.ContentType;
18import com.android.build.transform.api.QualifiedContent.Scope;
19import com.android.build.transform.api.Transform;
20import com.android.build.transform.api.Context;
21import com.android.build.transform.api.TransformInput;
22import com.android.build.transform.api.TransformOutputProvider;
23import com.android.build.transform.api.TransformException;
24import com.android.build.gradle.internal.pipeline.TransformManager;
25import com.android.build.transform.api.Format;
26// Top-level build file where you can add dataBindingConfiguration options common to all sub-projects/modules.
27
28buildscript {
29    dependencies {
30        classpath "com.android.tools.build:gradle:${dataBindingConfig.androidPluginVersion}"
31        // NOTE: Do not place your application dependencies here; they belong
32        // in the individual module build.gradle files
33    }
34}
35
36apply plugin: 'com.android.library'
37
38android {
39    compileSdkVersion dataBindingConfig.compileSdkVersion
40    buildToolsVersion dataBindingConfig.buildToolsVersion
41
42    defaultConfig {
43        minSdkVersion 7
44        targetSdkVersion 23
45        versionCode 1
46        versionName "1.0"
47    }
48    compileOptions {
49        sourceCompatibility JavaVersion.VERSION_1_6
50        targetCompatibility JavaVersion.VERSION_1_6
51    }
52    buildTypes {
53        release {
54            minifyEnabled false
55        }
56    }
57    packagingOptions {
58        exclude 'META-INF/services/javax.annotation.processing.Processor'
59        exclude 'META-INF/LICENSE.txt'
60        exclude 'META-INF/NOTICE.txt'
61        exclude 'android/databinding/DataBinderMapper.class'
62    }
63}
64
65configurations {
66    jarArchives
67}
68
69
70dependencies {
71    compile 'com.android.support:support-v4:21.0.3'
72    compile "com.android.databinding:baseLibrary:${dataBindingConfig.version}"
73}
74
75//create jar tasks
76android.libraryVariants.all { variant ->
77    def name = variant.buildType.name
78
79    if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {
80        return; // Skip debug builds.
81    }
82    def suffix = name.capitalize()
83
84    def javadocTask = project.tasks.create(name: "javadoc${suffix}", type: Javadoc) {
85        source variant.javaCompile.source
86        classpath = files(variant.javaCompile.classpath.files) + files(
87                "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar")
88    }
89
90    def javadocJarTask = project.tasks.create(name: "javadocJar${suffix}", type: Jar) {
91        classifier = 'javadoc'
92        from 'build/docs/javadoc'
93    }
94    javadocJarTask.dependsOn javadocTask
95
96    def sourcesJarTask = project.tasks.create(name: "sourceJar${suffix}", type: Jar) {
97        classifier = 'sources'
98        from android.sourceSets.main.java.srcDirs
99    }
100
101    artifacts.add('archives', javadocJarTask);
102    artifacts.add('archives', sourcesJarTask);
103}
104uploadArchives {
105    repositories {
106        mavenDeployer {
107            pom.artifactId = 'library'
108            pom.project {
109                licenses {
110                    license {
111                        name dataBindingConfig.licenseName
112                        url dataBindingConfig.licenseUrl
113                        distribution dataBindingConfig.licenseDistribution
114                    }
115                }
116            }
117        }
118    }
119}
120
121class ExcludeShimTransform extends Transform {
122    Project project;
123    public ExcludeShimTransform(Project project) {
124        this.project = project;
125    }
126    public Set<ContentType> getInputTypes() {
127        return TransformManager.CONTENT_CLASS;
128    }
129
130    public Set<Scope> getScopes() {
131        def result = new HashSet<Scope>();
132        result.add(Scope.PROJECT);
133        return result;
134    }
135
136    public Set<Scope> getReferencedScopes() {
137        return TransformManager.SCOPE_FULL_LIBRARY;
138    }
139
140    public boolean isIncremental() {
141        return false;
142    }
143
144    public String getName() {
145        return "DataBindingExcludeShimTransform";
146    }
147
148    public void transform(Context context, Collection<TransformInput> inputs,
149            Collection<TransformInput> referencedInputs,
150            TransformOutputProvider outputProvider,
151            boolean isIncremental) throws IOException, TransformException, InterruptedException {
152        inputs.each { transformInput ->
153            transformInput.getDirectoryInputs().each {
154                File outputDir = outputProvider.getContentLocation("data-binding-filtered",
155                        it.getContentTypes(), it.getScopes(), Format.DIRECTORY);
156                outputDir.delete();
157                outputDir.mkdirs();
158                FileTree tree = project.fileTree(dir: it.getFile())
159                tree.include '**/*.class'
160                tree.exclude 'android/databinding/DataBindingComponent.*'
161                tree.exclude 'android/databinding/DataBinderMapper.*'
162                tree.copy {
163                    into outputDir
164                }
165            }
166        }
167    }
168}
169
170android.registerTransform(new ExcludeShimTransform(project))
171
172task prebuildAar(type : Copy) {
173    dependsOn uploadArchives
174    from "$buildDir/outputs/aar/library-release.aar"
175    into dataBindingConfig.prebuildFolder
176    rename { String fileName ->
177        "databinding-library.aar"
178    }
179}
180