aboutsummaryrefslogtreecommitdiff
path: root/runners/maven-plugin/build.gradle
blob: a9a77a8ba1e6bbbfbf1d5af0cac184923a76eeb1 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import groovy.io.FileType
import org.jetbrains.CrossPlatformExec
import shadow.org.apache.commons.io.FileUtils

import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.nio.file.attribute.BasicFileAttributes


apply plugin: 'kotlin'
apply plugin: 'com.github.johnrengelman.shadow'


dependencies {
    shadow project(":runners:fatjar")
    shadow "org.apache.maven:maven-core:$maven_version"
    shadow "org.apache.maven:maven-model:$maven_version"
    shadow "org.apache.maven:maven-plugin-api:$maven_version"
    shadow "org.apache.maven:maven-archiver:$maven_archiver_version"
    shadow "org.codehaus.plexus:plexus-utils:$plexus_utils_version"
    shadow "org.codehaus.plexus:plexus-archiver:$plexus_archiver_version"
    shadow "org.apache.maven.plugin-tools:maven-plugin-annotations:$maven_plugin_tools_version"
}

task generatePom() {
    inputs.file(new File(projectDir, "pom.tpl.xml"))
    outputs.file(new File(buildDir, "pom.xml"))
    doLast {
        final pomTemplate = new File(projectDir, "pom.tpl.xml")
        final pom = new File(buildDir, "pom.xml")
        pom.text = pomTemplate.text.replace("<version>dokka_version</version>", "<version>$dokka_version</version>")
                .replace("<maven.version></maven.version>", "<maven.version>$maven_version</maven.version>")
                .replace("<version>maven-plugin-plugin</version>", "<version>$maven_plugin_tools_version</version>")
    }
}

task mergeClassOutputs doLast {
    def sourceDir = new File(buildDir, "classes/kotlin")
    def targetDir = new File(buildDir, "classes/java")

    sourceDir.eachFileRecurse FileType.ANY, {
        def filePath = it.toPath()
        def targetFilePath = targetDir.toPath().resolve(sourceDir.toPath().relativize(filePath))
        if (it.isFile()) {
            Files.move(filePath, targetFilePath, StandardCopyOption.REPLACE_EXISTING)
        } else if (it.isDirectory()) {
            targetFilePath.toFile().mkdirs()
        }
    }
}

task pluginDescriptor(type: CrossPlatformExec) {
    workingDir buildDir
    commandLine mvn, '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:descriptor'

    dependsOn mergeClassOutputs
}

task helpMojo(type: CrossPlatformExec) {
    workingDir buildDir
    commandLine mvn, '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:helpmojo'

    dependsOn mergeClassOutputs
}

helpMojo.dependsOn generatePom
sourceSets.main.java.srcDir("$buildDir/generated-sources/plugin")
compileJava.dependsOn helpMojo

pluginDescriptor.dependsOn generatePom

shadowJar {
    baseName = 'dokka-maven-plugin'
    classifier = ''
}

shadowJar.dependsOn pluginDescriptor


task sourceJar(type: Jar) {
    from sourceSets.main.allSource
}

apply plugin: 'maven-publish'

publishing {
    publications {
        dokkaMavenPlugin(MavenPublication) { publication ->
            artifactId = 'dokka-maven-plugin'

            artifact sourceJar {
                classifier "sources"
            }

            project.shadow.component(publication)

            pom.withXml {
                Node root = asNode()

                def dependency = new XmlParser().parseText('''
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <version>1.8.0</version>
                    <scope>system</scope>
                    <systemPath>${toolsjar}</systemPath>
                </dependency>
                ''')

                root.children().find {
                    return it.name() == "dependencies"
                }.append(dependency)

                def profiles = new XmlParser().parseText('''
                <profiles>
                    <profile>
                        <id>default-profile</id>
                        <activation>
                            <activeByDefault>true</activeByDefault>
                            <file>
                                <exists>${java.home}/../lib/tools.jar</exists>
                            </file>
                        </activation>
                        <properties>
                            <toolsjar>${java.home}/../lib/tools.jar</toolsjar>
                        </properties>
                    </profile>
                    <profile>
                        <id>mac-profile</id>
                        <activation>
                            <activeByDefault>false</activeByDefault>
                            <file>
                                <exists>${java.home}/../Classes/classes.jar</exists>
                            </file>
                        </activation>
                        <properties>
                            <toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
                        </properties>
                    </profile>
                </profiles>
                ''')
                root.append(profiles)
            }


        }
    }
}

bintrayPublication(project, ['dokkaMavenPlugin'])