xref: /aosp_15_r20/external/kotlinx.atomicfu/atomicfu-maven-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: 'maven-publish'
7
8apply from: rootProject.file('gradle/compile-options.gradle')
9
10ext.configureKotlin()
11
12dependencies {
13    api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
14    api project(":atomicfu-transformer")
15    api "org.apache.maven:maven-core:$maven_version"
16    api "org.apache.maven:maven-plugin-api:$maven_version"
17    api 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.5'
18}
19
20def outputDir = compileKotlin.destinationDirectory
21
22publishing.publications {
23    maven(MavenPublication) {
24        MavenPomConfiguration.configureMavenPluginPomAttributes(pom, project, outputDir.get().getAsFile().path)
25    }
26}
27
28String mavenUserHome = System.getProperty("maven.user.home")
29String mavenRepoLocal = System.getProperty("maven.repo.local")
30
31def pomFile = tasks.named("generatePomFileForMavenPublication", GenerateMavenPom).map { it.destination }.get()
32
33// runs the plugin description generator
34task generatePluginDescriptor(type: Exec, dependsOn: [generatePomFileForMavenPublication, ':atomicfu-transformer:publishToMavenLocal']) {
35    def pluginDescriptorFile = outputDir.file('META-INF/maven/plugin.xml')
36
37    workingDir projectDir
38    boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0
39    def args = isWindows ? ['cmd', '/c', 'mvnw.cmd'] : ['sh', './mvnw']
40    if (mavenUserHome != null) args.add("-Dmaven.user.home=${new File(mavenUserHome).getAbsolutePath()}")
41    if (mavenRepoLocal != null) args.add("-Dmaven.repo.local=${new File(mavenRepoLocal).getAbsolutePath()}")
42    args.addAll([
43            '--settings', './settings.xml',
44            '--errors',
45            '--batch-mode',
46            '--file', pomFile.toString(),
47            'org.apache.maven.plugins:maven-plugin-plugin:3.5.1:descriptor'
48    ])
49    commandLine args
50    doLast {
51        def descriptorFile = pluginDescriptorFile.get().getAsFile()
52        assert descriptorFile, "$descriptorFile: was not generated"
53        logger.info("Plugin descriptor is generated in $descriptorFile")
54    }
55}
56
57project.jar.dependsOn(generatePluginDescriptor)
58