[go: nahoru, domu]

blob: 3b466e5c5c27b8e98a37b3c81d386587fae5b71c [file] [log] [blame]
Aurimas Liutikas92d97562017-11-13 13:54:27 -08001/*
Aurimas Liutikas526389b2018-02-27 14:01:24 -08002 * Copyright 2018 The Android Open Source Project
Aurimas Liutikas92d97562017-11-13 13:54:27 -08003 *
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 */
16
Aurimas Liutikas526389b2018-02-27 14:01:24 -080017package androidx.build
Aurimas Liutikas92d97562017-11-13 13:54:27 -080018
19import groovy.lang.Closure
Jeff Gastonce468a92020-01-08 12:51:16 -050020import org.gradle.api.GradleException
Aurimas Liutikas92d97562017-11-13 13:54:27 -080021import org.gradle.api.Project
22import java.util.ArrayList
23
24/**
Aurimas Liutikas2cc275f2019-04-04 19:33:53 +010025 * Extension for [AndroidXPlugin].
Aurimas Liutikas92d97562017-11-13 13:54:27 -080026 */
Aurimas Liutikasb63ef632019-04-01 04:37:49 -070027open class AndroidXExtension(val project: Project) {
Aurimas Liutikas92d97562017-11-13 13:54:27 -080028 var name: String? = null
Aurimas Liutikas75e93a02019-05-28 16:31:38 -070029 var mavenVersion: Version? = null
30 set(value) {
Jeff Gastonce468a92020-01-08 12:51:16 -050031 field = value
32 chooseProjectVersion()
Aurimas Liutikas75e93a02019-05-28 16:31:38 -070033 }
Oussama Ben Abdelbaki34f21e02019-02-27 13:38:27 -050034 var mavenGroup: LibraryGroup? = null
Jeff Gastonce468a92020-01-08 12:51:16 -050035 set(value) {
36 field = value
37 chooseProjectVersion()
38 }
Alan Viverette30a75642020-02-07 13:09:18 -050039
Jeff Gastonce468a92020-01-08 12:51:16 -050040 private fun chooseProjectVersion() {
41 val version: Version
42 val groupVersion: Version? = mavenGroup?.forcedVersion
43 val mavenVersion: Version? = mavenVersion
44 if (mavenVersion != null) {
Alan Viverette30a75642020-02-07 13:09:18 -050045 if (groupVersion != null && !isGroupVersionOverrideAllowed()) {
Jeff Gastonce468a92020-01-08 12:51:16 -050046 throw GradleException("Cannot set mavenVersion (" + mavenVersion +
47 ") for a project (" + project +
48 ") whose mavenGroup already specifies forcedVersion (" + groupVersion +
49 ")")
50 } else {
51 version = mavenVersion
52 }
53 } else {
54 if (groupVersion != null) {
55 version = groupVersion
56 } else {
57 return
58 }
59 }
60 project.version = if (isSnapshotBuild()) version.copy(extra = "-SNAPSHOT") else version
61 versionIsSet = true
62 }
Alan Viverette30a75642020-02-07 13:09:18 -050063
64 private fun isGroupVersionOverrideAllowed(): Boolean {
65 // Grant an exception to the same-version-group policy for artifacts that haven't shipped a
66 // stable API surface, e.g. 1.0.0-alphaXX, to allow for rapid early-stage development.
67 val version = mavenVersion
68 return version != null && version.major == 1 && version.minor == 0 && version.patch == 0 &&
69 version.isAlpha()
70 }
71
Jeff Gastonce468a92020-01-08 12:51:16 -050072 private var versionIsSet = false
73 fun isVersionSet(): Boolean {
74 return versionIsSet
75 }
Aurimas Liutikas92d97562017-11-13 13:54:27 -080076 var description: String? = null
77 var inceptionYear: String? = null
78 var url = SUPPORT_URL
79 private var licenses: MutableCollection<License> = ArrayList()
Aurimas Liutikas75e93a02019-05-28 16:31:38 -070080 var publish: Publish = Publish.NONE
Aurimas Liutikasbfef0932018-04-04 13:25:38 -070081 var failOnDeprecationWarnings = true
82
Jake Wharton792bd532018-09-13 16:49:07 -040083 var compilationTarget: CompilationTarget = CompilationTarget.DEVICE
84
Sergey Vasilinets9c246882017-12-11 18:31:29 -080085 /**
Sergey Vasilinetse8d12f22018-07-12 16:32:26 -070086 * It disables docs generation and api tracking for tooling modules like annotation processors.
87 * We don't expect such modules to be used by developers as libraries, so we don't guarantee
88 * any api stability and don't expose any docs about them.
Sergey Vasilinets9c246882017-12-11 18:31:29 -080089 */
Sergey Vasilinetse8d12f22018-07-12 16:32:26 -070090 var toolingProject = false
91
Aurimas Liutikas92d97562017-11-13 13:54:27 -080092 fun license(closure: Closure<*>): License {
93 val license = project.configure(License(), closure) as License
94 licenses.add(license)
95 return license
96 }
97
98 fun getLicenses(): Collection<License> {
99 return licenses
100 }
101
102 companion object {
103 @JvmField
Sergey Vasilinetse8d12f22018-07-12 16:32:26 -0700104 val ARCHITECTURE_URL =
105 "https://developer.android.com/topic/libraries/architecture/index.html"
Aurimas Liutikas92d97562017-11-13 13:54:27 -0800106 @JvmField
Jake Wharton5c15cfa2019-06-06 10:27:43 -0400107 val SUPPORT_URL = "https://developer.android.com/jetpack/androidx"
Oussama Ben Abdelbaki34f21e02019-02-27 13:38:27 -0500108 val DEFAULT_UNSPECIFIED_VERSION = "unspecified"
Aurimas Liutikas92d97562017-11-13 13:54:27 -0800109 }
110}
111
Jake Wharton792bd532018-09-13 16:49:07 -0400112enum class CompilationTarget {
113 /** This library is meant to run on the host machine (like an annotation processor). */
114 HOST,
115 /** This library is meant to run on an Android device. */
116 DEVICE
117}
118
Nick Anthonyeece3f42019-11-08 10:20:40 -0500119/**
120 * Publish Enum:
121 * Publish.NONE -> Generates no aritfacts; does not generate snapshot artifacts
122 * or releasable maven artifacts
123 * Publish.SNAPSHOT_ONLY -> Only generates snapshot artifacts
124 * Publish.SNAPSHOT_AND_RELEASE -> Generates both snapshot artifacts and releasable maven artifact
125*/
Aurimas Liutikas75e93a02019-05-28 16:31:38 -0700126enum class Publish {
127 NONE, SNAPSHOT_ONLY, SNAPSHOT_AND_RELEASE;
128
129 fun shouldRelease() = this == SNAPSHOT_AND_RELEASE
130 fun shouldPublish() = this == SNAPSHOT_ONLY || this == SNAPSHOT_AND_RELEASE
131}
132
Aurimas Liutikas92d97562017-11-13 13:54:27 -0800133class License {
134 var name: String? = null
135 var url: String? = null
Jake Wharton585b8f92018-07-09 13:34:52 -0400136}