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 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
18 
<lambda>null19 plugins {
20     alias(libs.plugins.kotlinJvm)
21     application
22 }
23 
24 group = "androidx.build"
25 version = "1.0-SNAPSHOT"
26 
27 // create a config file that ships in resources so that we can detect the repository layout at
28 // runtime.
<lambda>null29 val writeConfigPropsTask = tasks.register("prepareEnvironmentProps", WriteProperties::class) {
30     description =  "Generates a properties file with the current environment"
31     setOutputFile(project.layout.buildDirectory.map {
32         it.file("importMavenConfig.properties")
33     })
34     property("supportRoot", project.projectDir.resolve("../../").canonicalPath)
35 }
36 
<lambda>null37 val createPropertiesResourceDirectoryTask = tasks.register("createPropertiesResourceDirectory", Copy::class) {
38     description = "Creates a directory with the importMaven properties which can be set" +
39             " as an input directory to the java resources"
40     from(writeConfigPropsTask.map { it.outputFile })
41     into(project.layout.buildDirectory.dir("environmentConfig"))
42 }
43 
<lambda>null44 java {
45     sourceCompatibility = JavaVersion.VERSION_17
46     targetCompatibility = JavaVersion.VERSION_17
47     sourceSets {
48         main {
49             resources.srcDir(createPropertiesResourceDirectoryTask.map { it.destinationDir })
50         }
51     }
52 }
<lambda>null53 tasks.withType(KotlinCompile::class.java).configureEach { kotlinOptions { jvmTarget = "17" } }
54 
<lambda>null55 dependencies {
56     implementation(libs.kotlinGradlePlugin)
57     implementation(gradleTestKit())
58     implementation(libs.kotlinCoroutinesCore)
59     implementation(importMavenLibs.okio)
60     implementation(importMavenLibs.bundles.ktorServer)
61     implementation(importMavenLibs.ktorClientOkHttp)
62     implementation(importMavenLibs.clikt)
63     implementation(importMavenLibs.bundles.log4j)
64     testImplementation(kotlin("test"))
65     testImplementation(libs.junit)
66     testImplementation(libs.truth)
67     testImplementation(importMavenLibs.okioFakeFilesystem)
68 }
69 
70 
71 // b/250726951 Gradle ProjectBuilder needs reflection access to java.lang.
72 val jvmAddOpensArgs = listOf("--add-opens=java.base/java.lang=ALL-UNNAMED")
<lambda>null73 tasks.withType<Test>() {
74     this.jvmArgs(jvmAddOpensArgs)
75 }
<lambda>null76 application {
77     mainClass.set("androidx.build.importMaven.MainKt")
78     applicationDefaultJvmArgs += jvmAddOpensArgs
79 }
80 
<lambda>null81 tasks.named("installDist", Sync::class).configure {
82     // some jars will be duplicate, we can pick any since they are
83     // versioned.
84     duplicatesStrategy = DuplicatesStrategy.EXCLUDE
85 }
86