-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
238 lines (218 loc) · 10.6 KB
/
build.gradle
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
227
228
229
230
231
232
233
234
235
236
237
238
import de.materna.fegen.build.ArtifactData
import de.materna.fegen.build.license.LicensePlugin
import groovy.swing.SwingBuilder
buildscript {
ext {
kotlin_version = '1.4.32'
fegen_snapshot = false
fegen_core_version = '1.0-RC9'
fegen_gradle_version = '1.0-RC9'
fegen_maven_version = '1.0-RC9'
fegen_kotlin_version = '1.0-RC9'
fegen_kotlin_gradle_version = '1.0-RC9'
fegen_kotlin_maven_version = '1.0-RC9'
fegen_kotlin_runtime_version = '1.0-RC9'
fegen_spring_util_version = '1.0-RC9'
fegen_web_version = '1.0-RC9'
fegen_web_gradle_version = '1.0-RC9'
fegen_web_maven_version = '1.0-RC9'
// Version of web runtime needs to be set in package.json
queryPassword = { title, text ->
def result = ""
new SwingBuilder().edt {
dialog(modal: true, title: title, alwaysOnTop: true, resizable: true, locationRelativeTo: null, pack: true, show: true) {
vbox {
label(text: text)
input = passwordField()
button(defaultButton: true, text: "OK", actionPerformed: {
result = new String(input.password)
dispose()
})
}
}
}
if (result.isEmpty()) {
throw new GradleException("No password specified")
}
return result
}
kotlinArtifact = { closure ->
def data = new ArtifactData()
closure.delegate = data
closure()
data.artifactProject.compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
data.artifactProject.compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
data.artifactProject.sourceCompatibility = '1.8'
data.artifactProject.targetCompatibility = '1.8'
def javaExt = data.artifactProject.extensions.getByName("java")
javaExt.withJavadocJar()
javaExt.withSourcesJar()
data.artifactProject.publishing {
publications {
mavenKotlin(MavenPublication) {
artifactId = data.artifactId
from data.artifactProject.components.java
pom {
name = data.artifactName
description = data.artifactDescription
url = "https://github.com/materna-se/fegen"
license {
name = "MIT"
url = "http://www.opensource.org/licenses/mit-license.php"
}
developers {
developer {
name = "Johannes Neubauer"
email = "[email protected]"
organization = "Materna Information & Communications SE"
organizationUrl = "https://www.materna.de"
}
}
scm {
connection = "scm:git:git://github.com/materna-se/fegen.git"
developerConnection = "scm:git:git://github.com/materna-se/fegen.git"
url = "https://github.com/materna-se/fegen/tree/master"
}
}
}
}
repositories {
maven {
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
url = data.artifactProject.fegen_snapshot ? snapshotRepoUrl : releasesRepoUrl
if (project.ext.has("mavenCentral.username") && project.ext.has("mavenCentral.password")) {
credentials {
// The username should be stored in "$HOME/.gradle/gradle.properties"
username = project.ext.get("mavenCentral.username")
password = project.ext.getProperty("mavenCentral.password")
}
}
}
}
}
if (project.hasProperty("signing.keyId") && project.hasProperty("signing.secretKeyRingFile")) {
data.artifactProject.signing {
sign data.artifactProject.publishing.publications.mavenKotlin
}
}
}
// Use maven to generate a plugin.xml when publishing a plugin
mavenPlugin = { Project project ->
project.tasks.create("addPluginXml", Exec.class) {
// Task depends on the built kotlin class files
mustRunAfter "compileKotlin"
// let the following task generate a pom.xml
dependsOn "generatePomFileForMavenKotlinPublication"
def pomDestination = new File("${project.projectDir}/pom.xml")
// Temporarily copy the pom.xml to the project dir to make the project look like a maven project
doFirst {
def pomSource = new File("${project.buildDir}/publications/mavenKotlin/pom-default.xml")
def pomParts = pomSource.text.split("</artifactId>")
pomDestination.withWriter { writer ->
writer.append pomParts.head() + "</artifactId>\n"
writer.append " <packaging>maven-plugin</packaging>\n"
// This later tells maven where to read class files and where to put the plugin.xml
writer.append " <build>\n"
writer.append " <directory>${project.projectDir}</directory>\n"
writer.append " <outputDirectory>${project.buildDir}/classes/kotlin/main</outputDirectory>\n"
writer.append " </build>\n"
writer.append pomParts.tail().join("</artifactId>")
}
pomDestination.deleteOnExit()
}
def isWindows = File.separator != "/"
def mvnw = isWindows ? "mvnw.cmd" : "mvnw"
// Let maven generate the plugin.xml
commandLine "${project.projectDir}/$mvnw", "-e", "-B", "org.apache.maven.plugins:maven-plugin-plugin:3.6.0:descriptor"
doLast {
pomDestination.delete()
}
}
// plugin.xml must be added to compiled files before jar is built
project.assemble {
mustRunAfter "addPluginXml"
}
// Task must run when any publish tasks should be run
project.tasks.each { task ->
if (task instanceof PublishToMavenLocal || task instanceof PublishToMavenRepository) {
task.dependsOn "addPluginXml"
}
}
}
}
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.5.RELEASE"
}
}
plugins {
id "org.springframework.boot" version "2.2.4.RELEASE" apply false
id "org.jetbrains.kotlin.jvm" version "$kotlin_version" apply false
id "org.jetbrains.kotlin.plugin.jpa" version "$kotlin_version" apply false
id "io.spring.dependency-management" version "1.0.10.RELEASE" apply false
}
apply plugin: 'base'
apply plugin: LicensePlugin
license {
includes = [
"**/src/main/**/*.kt",
"**/src/test/**/*.kt",
"**/src/main/**/*.java",
"**/src/test/**/*.java",
"**/*.swift",
"fegen-kotlin/fegen-kotlin-android-runtime/**/*.kt",
"fegen-web/fegen-web-runtime/src/**/*.ts",
"fegen-examples/fegen-example-gradle/web-api/src/tests/**/*.ts",
"fegen-examples/fegen-example-gradle/web-frontend/src/**/*.ts",
"fegen-examples/fegen-example-gradle/web-frontend/src/**/*.tsx"
]
excludes = [
"fegen-examples/fegen-example-gradle/kotlin-api/src/main/kotlin/**/api/**/*.kt",
"fegen-examples/fegen-example-gradle/web-frontend/src/*.ts",
"fegen-examples/fegen-example-gradle/web-frontend/src/*.tsx",
"fegen-examples/fegen-example-maven/kotlin-api/src/main/kotlin/**/api/**/*.kt"
]
}
gradle.taskGraph.whenReady { taskGraph ->
def missingConfig = false
if (taskGraph.allTasks.any { it instanceof PublishToMavenRepository }) {
if (!project.ext.has("mavenCentral.username")) {
logger.error("Please specify the property mavenCentral.username")
logger.error("in your \"\$HOME/.gradle/gradle.properties\" file")
missingConfig = true
}
if (!project.ext.has("mavenCentral.password")) {
logger.error("Please specify the property mavenCentral.password")
logger.error("in your \"\$HOME/.gradle/gradle.properties\" file")
missingConfig = true
}
}
if (taskGraph.allTasks.any { it instanceof Sign || (it instanceof PublishToMavenRepository && !project.ext.fegen_snapshot) }) {
if (!project.hasProperty("signing.keyId") || !project.hasProperty("signing.secretKeyRingFile")) {
logger.error("Please add the following properties in your \"\$HOME/.gradle/gradle.properties\" file:")
logger.error("signing.keyId=0123ABCD")
logger.error("signing.secretKeyRingFile=path/to/secring.gpg")
missingConfig = true
} else {
def id = project.getProperties().get("signing.keyId")
if (!project.hasProperty("signing.password")) {
def password = queryPassword("Gradle artifact signing", "To publish artifacts they must be signed. Please enter the password for the key with ID $id")
allprojects {
ext."signing.password" = password
}
}
}
}
if (missingConfig) {
throw new GradleException("The gradle.properties file in your home directory is missing properties. Refer to the previous log output to see which ones.")
}
}