File: commonConfiguration.gradle

package info (click to toggle)
kotlin 1.3.31%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 109,524 kB
  • sloc: java: 454,753; xml: 18,599; javascript: 10,452; sh: 513; python: 97; makefile: 54; ansic: 4
file content (226 lines) | stat: -rw-r--r-- 7,841 bytes parent folder | download | duplicates (2)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
ext.configureJvmProject = { Project project ->
    project.configure(project) {
        task sourcesJar(type: Jar, dependsOn: classes) {
            classifier = 'sources'
            from sourceSets.main.kotlin
        }

        tasks.withType(JavaCompile) {
            options.fork = true
            options.forkOptions.javaHome = file(JDK_18)
        }

        tasks.withType(project.compileKotlin.class) {
            kotlinOptions.jdkHome = JDK_18
        }

        test {
            executable = "$JDK_16/bin/java"
        }
    }
}

ext.configureJavaOnlyJvm6Project = { Project project ->
    project.tasks.withType(JavaCompile) {
        sourceCompatibility = 1.6
        targetCompatibility = 1.6
        options.fork = true
        options.forkOptions.javaHome = file(JDK_16)
    }
}

ext.configureJvm6Project = { Project project ->
    project.configure(project) {
        project.ext.jvmTarget = "1.6"
        project.ext.javaHome = JDK_16

        task sourcesJar(type: Jar, dependsOn: classes) {
            classifier = 'sources'
            from sourceSets.main.kotlin
        }

        configureJavaOnlyJvm6Project(project)

        tasks.withType(project.compileKotlin.class) {
            kotlinOptions.jdkHome = JDK_16
            kotlinOptions.jvmTarget = "1.6"
        }

        test {
            executable = "$JDK_16/bin/java"
        }
    }
}

ext.compileJava9Sources = { Project project, String moduleName, Collection<FileCollection> moduleOutputs = [project.sourceSets.main.output] ->
    // module-info.java should be in java9 source set by convention
    SourceDirectorySet java9SourceSet = project.sourceSets.java9.java
    project.tasks.getByName("compileJava9Java").configure { JavaCompile it ->
        dependsOn(moduleOutputs)
        it.sourceCompatibility = 1.9
        it.targetCompatibility = 1.9
        it.destinationDir = file("${java9SourceSet.outputDir}/META-INF/versions/9")
        it.options.fork = true
        it.options.forkOptions.javaHome = file(JDK_9)
        it.options.sourcepath = files(java9SourceSet.srcDirs)

        doFirst {
            def moduleFiles = files(*moduleOutputs)
            def modulePath = project.configurations.compileClasspath.filter { !(it in moduleFiles.files) }

            options.compilerArgs = [
                    '--module-path', modulePath.asPath,
                    '--patch-module', "$moduleName=${moduleFiles.asPath}"
            ]

            classpath = files()
        }
    }
}

ext.manifestAttributes = { Manifest manifest, Project project, String component = null, boolean multiRelease = false ->
    project.configure(manifest) {
        attributes \
                'Implementation-Vendor': 'JetBrains',
                'Implementation-Title': project.archivesBaseName,
                'Implementation-Version': project.buildNumber

        if (component != null) {
            attributes \
                'Kotlin-Runtime-Component': component,
                'Kotlin-Version': project.kotlinLanguageVersion
        }
        if (multiRelease) {
            attributes \
                'Multi-Release': 'true'
        }
    }
}

task preparePublication {
    def properties = project.properties
    assert project.version != 'unspecified'

    Map<String, String> repositoryProviders = ['sonatype-nexus-staging' : 'sonatype', 'sonatype-nexus-snapshots' : 'sonatype']
    project.ext.isRelease = !project.version.toString().contains('-SNAPSHOT')

    String repo = properties["deployRepo"] ?: properties['deploy-repo']
    String repoProvider = repositoryProviders.get(repo, repo)
    project.ext.isSonatypePublish = repoProvider == 'sonatype'
    project.ext.isSonatypeRelease = isSonatypePublish && isRelease

    project.ext['signing.keyId'] = project.properties['kotlin.key.name']
    project.ext['signing.password'] = project.properties['kotlin.key.passphrase']

    String sonatypeSnapshotsUrl = (isSonatypePublish && !isRelease) ? "https://oss.sonatype.org/content/repositories/snapshots/" : null

    ext.repoUrl = properties["deployRepoUrl"] ?: sonatypeSnapshotsUrl ?: properties["deploy-url"] ?: "file://${rootProject.buildDir}/repo".toString()
    ext.username = properties["deployRepoUsername"] ?: properties["kotlin.${repoProvider}.user"]
    ext.password = properties["deployRepoPassword"] ?: properties["kotlin.${repoProvider}.password"]

    logger.info("Deployment repository preliminary url: $repoUrl ($repoProvider)")

    doLast {
        println("Deployment repository url: $repoUrl")
    }
}

ext.signPom = { Project project, MavenDeployer deployer ->
    deployer.beforeDeployment { MavenDeployment deployment ->
        if (project.signing.required)
            project.signing.signPom(deployment)
    }
}

ext.configureDist = { Project project ->
    project.configure(project) {
        configurations {
            distJar
        }

        task dist(type: Copy, dependsOn: assemble) {
            rename "-${java.util.regex.Pattern.quote(version)}", ''
            into distLibDir
            afterEvaluate {
                project.artifacts {
                    distJar file: file("$distLibDir${File.separator}${archivesBaseName}.jar"), builtBy: "dist"
                }
            }
        }
    }
}

ext.configurePublishing = { Project project ->
    project.configure(project) {
        apply plugin: 'maven'

        if (!project.hasProperty('prebuiltJar')) {
            apply plugin: 'signing'

            signing {
                required { (project.properties["signingRequired"] ?: project.isSonatypeRelease) }
                sign configurations.archives
            }

            signArchives {
                enabled signing.required
            }
        }

        uploadArchives {
            def prepareTask = rootProject.preparePublication
            dependsOn prepareTask

            doFirst {
                repositories.mavenDeployer.repository.url = prepareTask.repoUrl
            }

            repositories {
                mavenDeployer {
                    signPom(project, it)

                    repository(url: prepareTask.repoUrl) {
                        authentication(userName: prepareTask.username, password: prepareTask.password)
                    }
                    pom.project {
                        name "${project.group}:${project.name}"
                        packaging 'jar'
                        // optionally artifactId can be defined here
                        description project.description
                        url 'https://kotlinlang.org/'
                        licenses {
                            license {
                                name 'The Apache License, Version 2.0'
                                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                            }
                        }
                        scm {
                            url 'https://github.com/JetBrains/kotlin'
                            connection 'scm:git:https://github.com/JetBrains/kotlin.git'
                            developerConnection 'scm:git:https://github.com/JetBrains/kotlin.git'
                        }
                        developers {
                            developer {
                                name 'Kotlin Team'
                                organization = 'JetBrains'
                                organizationUrl 'https://www.jetbrains.com'
                            }
                        }
                    }
                }
            }
        }

        task publish(dependsOn: uploadArchives)
    }
}

allprojects { project ->
    project.ext.javadocJar = { lambda = {} ->
        ArtifactsKt.javadocJar(project, lambda)
    }
    
    dependencies.ext.kotlinStdlib = { suffix ->
        DependenciesKt.kotlinStdlib(project, suffix)
    }
}