xref: /aosp_15_r20/external/kotlinx.atomicfu/atomicfu-gradle-plugin/build.gradle (revision 68017707106cb9da9fed635c150bc497c09c160f)
1/*
2 * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5apply plugin: 'kotlin'
6apply plugin: 'java-gradle-plugin'
7
8// Gradle plugin must be compiled targeting the same Kotlin version as used by Gradle
9kotlin.sourceSets.configureEach {
10    languageSettings {
11        languageVersion = KotlinConfiguration.getOverridingKotlinLanguageVersion(project) ?: "1.4"
12        apiVersion = KotlinConfiguration.getOverridingKotlinApiVersion(project) ?: "1.4"
13    }
14}
15
16dependencies {
17    implementation(project(":atomicfu-transformer")) {
18        exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib'
19    }
20
21    compileOnly gradleApi()
22    compileOnly 'org.jetbrains.kotlin:kotlin-stdlib'
23    compileOnly "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
24    // Atomicfu compiler plugin dependency will be loaded to kotlinCompilerPluginClasspath
25    // Atomicfu plugin will only be applied if the flag is set kotlinx.atomicfu.enableJsIrTransformation=true
26    implementation "org.jetbrains.kotlin:atomicfu:$kotlin_version"
27
28    testImplementation gradleTestKit()
29    testImplementation 'org.jetbrains.kotlin:kotlin-test'
30    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
31    testImplementation 'junit:junit:4.12'
32}
33
34configurations {
35    testPluginClasspath {
36        attributes {
37            attribute(
38                    Usage.USAGE_ATTRIBUTE,
39                    project.objects.named(Usage.class, Usage.JAVA_RUNTIME)
40            )
41            attribute(
42                    Category.CATEGORY_ATTRIBUTE,
43                    project.objects.named(Category.class, Category.LIBRARY)
44            )
45        }
46    }
47}
48
49dependencies {
50    testPluginClasspath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
51}
52
53evaluationDependsOn(':atomicfu')
54def atomicfu = project(':atomicfu')
55def atomicfuJvmJarTask = atomicfu.tasks.getByName(atomicfu.kotlin.targets.jvm.artifactsTaskName)
56
57def jsLegacy = atomicfu.kotlin.targets.hasProperty("jsLegacy")
58        ? atomicfu.kotlin.targets.jsLegacy
59        : atomicfu.kotlin.targets.js
60def atomicfuJsJarTask = atomicfu.tasks.getByName(jsLegacy.artifactsTaskName)
61
62def atomicfuMetadataOutput = atomicfu.kotlin.targets.metadata.compilations["main"].output.allOutputs
63
64// Write the plugin's classpath to a file to share with the tests
65task createClasspathManifest {
66    dependsOn(atomicfuJvmJarTask)
67    dependsOn(atomicfuJsJarTask)
68    dependsOn(atomicfuMetadataOutput)
69
70    def outputDir = file("$buildDir/$name")
71    outputs.dir outputDir
72
73    doLast {
74        outputDir.mkdirs()
75        file("$outputDir/plugin-classpath.txt").text = (sourceSets.main.runtimeClasspath + configurations.testPluginClasspath).join("\n")
76        file("$outputDir/atomicfu-jvm.txt").text = atomicfuJvmJarTask.archivePath
77        file("$outputDir/atomicfu-js.txt").text = atomicfuJsJarTask.archivePath
78        file("$outputDir/atomicfu-metadata.txt").text = atomicfuMetadataOutput.join("\n")
79    }
80}
81
82task createKotlinRepoUrlResource {
83    def customKotlinRepoUrl = KotlinConfiguration.getCustomKotlinRepositoryURL(project)
84    if (customKotlinRepoUrl == null) return
85
86    def outputDir = file("$buildDir/$name")
87    outputs.dir outputDir
88
89    doLast {
90        outputDir.mkdirs()
91        file("$outputDir/kotlin-repo-url.txt").text = customKotlinRepoUrl
92    }
93}
94
95// Add the classpath file to the test runtime classpath
96dependencies {
97    testRuntimeOnly files(createClasspathManifest)
98    testRuntimeOnly files(createKotlinRepoUrlResource)
99}
100