1/*
2 * Copyright 2022 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 */
16
17/**
18 * This file was created using the `create_project.py` script located in the
19 * `<AndroidX root>/development/project-creator` directory.
20 *
21 * Please use that script when creating a new project, rather than copying an existing project and
22 * modifying its settings.
23 */
24import androidx.build.SoftwareType
25
26plugins {
27    id("AndroidXPlugin")
28    id("kotlin")
29    id("java-gradle-plugin")
30}
31
32// This custom configuration ensures that dependencies used in tests with gradle test kit with
33// generated build.gradle are considered when determining which tests to run on CI due to a change.
34// For reference: b/281515796
35configurations {
36    neededForGradleTestKit {
37        canBeResolved = true
38    }
39    neededForGradleTestKitAgp81 {
40        canBeResolved = true
41    }
42}
43
44dependencies {
45    compileOnly(libs.androidGradlePlugin)
46    compileOnly(libs.kotlinGradlePlugin)
47
48    implementation(gradleApi())
49    implementation("com.google.protobuf:protobuf-java:3.22.3")
50    implementation(libs.agpTestingPlatformCoreProto)
51
52    testImplementation(gradleTestKit())
53    testImplementation(project(":internal-testutils-gradle-plugin"))
54    testImplementation(libs.junit)
55    testImplementation(libs.kotlinTest)
56    testImplementation(libs.truth)
57
58    neededForGradleTestKit(libs.androidGradlePlugin)
59    neededForGradleTestKit(libs.kotlinGradlePlugin)
60    neededForGradleTestKit(libs.kotlinStdlib)
61
62    neededForGradleTestKitAgp81("com.android.tools.build:gradle:8.1.1")
63    neededForGradleTestKitAgp81("com.android.tools.build:aapt2:8.1.1-10154469")
64    neededForGradleTestKitAgp81("com.android.tools.build:aapt2:8.1.1-10154469:linux")
65    neededForGradleTestKitAgp81("com.android.tools.build:aapt2:8.1.1-10154469:osx")
66}
67
68tasks.withType(Test).configureEach {
69    it.dependsOn(configurations.neededForGradleTestKit)
70    it.dependsOn(configurations.neededForGradleTestKitAgp81)
71}
72
73gradlePlugin {
74    plugins {
75        baselineProfileProducer {
76            id = "androidx.baselineprofile.producer"
77            implementationClass = "androidx.baselineprofile.gradle.producer.BaselineProfileProducerPlugin"
78        }
79        baselineProfileConsumer {
80            id = "androidx.baselineprofile.consumer"
81            implementationClass = "androidx.baselineprofile.gradle.consumer.BaselineProfileConsumerPlugin"
82        }
83        baselineProfileAppTarget {
84            id = "androidx.baselineprofile.apptarget"
85            implementationClass = "androidx.baselineprofile.gradle.apptarget.BaselineProfileAppTargetPlugin"
86        }
87        baselineProfileWrapper {
88            id = "androidx.baselineprofile"
89            implementationClass = "androidx.baselineprofile.gradle.wrapper.BaselineProfileWrapperPlugin"
90        }
91    }
92}
93
94androidx {
95    name = "Baseline Profile Gradle Plugin"
96    type = SoftwareType.GRADLE_PLUGIN
97    inceptionYear = "2022"
98    description = "Android Baseline Profile Gradle Plugin"
99}
100
101tasks.withType(Test).configureEach { test ->
102    test.maxParallelForks = 2
103    test.javaLauncher = javaToolchains.launcherFor {
104        // Test on JDK 17 which supports lower versions of AGP. This can be removed
105        // once we move to AGP 8.2.1+
106        languageVersion = JavaLanguageVersion.of(17)
107    }
108}
109afterEvaluate { tasks.named("test") { it.dependsOn(tasks.named("publish")) } }
110