aboutsummaryrefslogtreecommitdiff
path: root/atomicfu-maven-plugin/build.gradle
blob: 8929be974a76d0fe2e6b203e0379fd9039bb06d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright 2017-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

apply plugin: 'kotlin'
apply plugin: 'maven'

apply from: rootProject.file('gradle/compile-options.gradle')

ext.configureKotlin()

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile project(":atomicfu-transformer")
    compile "org.apache.maven:maven-core:$maven_version"
    compile "org.apache.maven:maven-plugin-api:$maven_version"
    compile 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.5'
}

def pomFile = file("$buildDir/pom.xml")
def outputDir = compileKotlin.destinationDir
def buildSnapshots = rootProject.properties['build_snapshot_train'] != null

evaluationDependsOn(':atomicfu-transformer')

task generatePomFile(dependsOn: [compileKotlin, ':atomicfu-transformer:publishToMavenLocal']) {
    def buildDir = project.buildDir // because Maven model also has "project"
    outputs.file(pomFile)
    doLast {
        install.repositories.mavenInstaller.pom.with {
            groupId = project.group
            artifactId = project.name
            version = project.version
            packaging = 'maven-plugin'

            withXml {
                asNode().with {
                    appendNode('build').with {
                        appendNode('directory', buildDir)
                        appendNode('outputDirectory', outputDir)
                    }
                    appendNode('properties').with {
                        appendNode('project.build.sourceEncoding', 'UTF-8')
                    }
                    appendNode('repositories').with {
                        appendNode('repository').with {
                            appendNode('id', 'kotlin-eap')
                            appendNode('url', 'https://kotlin.bintray.com/kotlin-eap')
                        }

                        appendNode('repository').with {
                            appendNode('id', 'kotlin-dev')
                            appendNode('url', 'https://kotlin.bintray.com/kotlin-dev')
                        }

                        appendNode('repository').with {
                            appendNode('id', 'dev')
                            appendNode('url', 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev')
                        }

                        appendNode('repository').with {
                            appendNode('id', 'kotlinx')
                            appendNode('url', 'https://kotlin.bintray.com/kotlinx')
                        }

                        if (buildSnapshots) {
                            appendNode('repository').with {
                                appendNode('id', 'kotlin-snapshots')
                                appendNode('url', "https://oss.sonatype.org/content/repositories/snapshots")
                            }
                        }
                    }
                }
            }
        }
        install.repositories.mavenInstaller.pom.writeTo(pomFile)
        assert pomFile.file, "$pomFile: was not generated"
        logger.info("POM is generated in $pomFile")
    }
}

String mavenUserHome = System.getProperty("maven.user.home")
String mavenRepoLocal = System.getProperty("maven.repo.local")

// runs the plugin description generator
task generatePluginDescriptor(type: Exec, dependsOn: generatePomFile) {
    def pluginDescriptorFile = new File(outputDir, 'META-INF/maven/plugin.xml')

    workingDir projectDir
    boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0
    def args = isWindows ? ['cmd', '/c', 'mvnw.cmd'] : ['sh', './mvnw']
    if (mavenUserHome != null) args.add("-Dmaven.user.home=${new File(mavenUserHome).getAbsolutePath()}")
    if (mavenRepoLocal != null) args.add("-Dmaven.repo.local=${new File(mavenRepoLocal).getAbsolutePath()}")
    args.addAll([
        '--settings', './settings.xml',
        '--errors',
        '--batch-mode',
        '--file', pomFile.toString(),
        'org.apache.maven.plugins:maven-plugin-plugin:3.5.1:descriptor'
    ])
    commandLine args
    doLast {
        assert pluginDescriptorFile.file, "$pluginDescriptorFile: was not generated"
        logger.info("Plugin descriptor is generated in $pluginDescriptorFile")
    }
}

project.jar.dependsOn(generatePluginDescriptor)