-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
391 lines (351 loc) · 13 KB
/
build.gradle.kts
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.FileReader
import java.io.FileWriter
import java.util.*
repositories {
mavenLocal()
mavenCentral()
google()
jcenter()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
maven {
url = uri("https://maven.springframework.org/release")
}
maven {
url = uri("https://maven.restlet.com")
}
maven {
url = uri("https://dl.bintray.com/kotlin/kotlin-eap")
}
}
plugins {
id("groovy")
id("java")
id("java-gradle-plugin")
id("com.gradle.plugin-publish") version "0.12.0"
kotlin("jvm") version "1.4.32"
}
//println("fix sync intellij idea not showing")
apply {
from("build.test.gradle")
}
group = "com.dimaslanjaka"
version = getVersionPref(project)["version"]!!
description = "Transform gradle artifacts to maven local repository, for available offline with mavenLocal"
println("${project.name} using version ${project.version}")
sourceSets {
getByName("main") {
java.srcDir("${project.projectDir}/src/main/groovy")
java.srcDir("${project.projectDir}/src/main/java")
java.srcDir("${project.projectDir}/src/main/kotlin")
}
getByName("test") {
java.srcDir("${project.projectDir}/src/test/java")
java.srcDir("${project.projectDir}/src/test/kotlin")
}
}
// cache
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor(4, "hours")
cacheChangingModulesFor(4, "hours")
}
}
val offlineLib = File(projectDir, "repo/components/build/libs")
@Suppress("GradleDependency")
dependencies {
implementation(gradleApi())
implementation(localGroovy())
implementation(fileTree(mapOf("dir" to "lib", "include" to listOf("*.jar"))))
implementation(fileTree(mapOf("dir" to offlineLib, "include" to listOf("*.jar"))))
//Test
testImplementation(gradleTestKit())
testImplementation("junit:junit:4.13")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.1")
//testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.7.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.1")
//testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.7.1")
//testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
//kotlin deps
//implementation("org.jetbrains.kotlin:kotlin-reflect:1.4.32")
//implementation("org.jetbrains.kotlin:kotlin-stdlib:1.4.32")
//implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.32")
//implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.32")
compileOnly("org.jetbrains:annotations:16.0.2")
//compileOnly("com.android.tools.build:gradle:7.0.0-alpha03")
implementation("com.google.code.gson:gson:2.8.5")
//implementation("com.squareup:javapoet:1.10.0")
//implementation("com.squareup:kotlinpoet:1.0.0-RC1")
implementation("joda-time:joda-time:2.10.9")
//implementation("org.reflections:reflections:0.9.12")
//implementation("org.jboss:jdk-misc:2.Final")
implementation("org.jsoup:jsoup:1.13.1")
// package re-locator
//implementation("com.googlecode.jarjar:jarjar:1.3")
//implementation("org.apache.maven:maven-model-builder:3.6.3")
// Spring
implementation("org.springframework:spring-core:5.2.14.RELEASE")
// jsonschema2pojo
// Annotation
implementation("javax.annotation:javax.annotation-api:1.3.2")
// Required if generating JSR-303 annotations
implementation("javax.validation:validation-api:1.1.0.CR2")
// Required if generating Jackson 2 annotations
implementation("com.fasterxml.jackson.core:jackson-databind:2.12.1")
// Required if generating JodaTime data types
implementation("joda-time:joda-time:2.2")
// Apache
implementation("org.apache.commons:commons-lang3:3.11")
implementation("commons-validator:commons-validator:1.7")
implementation("org.apache.commons:commons-collections4:4.4")
implementation("commons-collections:commons-collections:3.2.2")
/*
implementation("commons-io:commons-io:2.8.0")
implementation("org.apache.httpcomponents:httpclient:4.5.13")
implementation("org.apache.commons:commons-collections4:4.3")
implementation("org.apache.commons:commons-compress:1.20")
implementation("org.apache.commons:commons-exec:1.3")
implementation("org.apache.commons:commons-math3:3.6.1")
implementation("commons-codec:commons-codec:1.9")
implementation("commons-net:commons-net:3.6")
implementation("commons-cli:commons-cli:1.4")
implementation("xerces:xercesImpl:2.12.0")
implementation("org.apache.cxf:cxf-common-utilities:2.5.11")
*/
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
tasks.withType<Jar>().configureEach {
archiveBaseName.set("gradle-plugin")
manifest {
attributes["Implementation-Title"] = project.description as String
attributes["Implementation-Version"] = project.version as String
attributes["Implementation-Vendor"] = "Dimas Lanjaka"
attributes["Created-By"] =
"${System.getProperty("java.version")} (${System.getProperty("java.vendor")} ${System.getProperty("java.vm.version")})"
}
}
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(arrayOf("-parameters", "-Xdoclint:none", "-Xlint:all"))
options.isIncremental = true
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}
tasks.withType<KotlinCompile>().all {
kotlinOptions {
suppressWarnings = true
jvmTarget = JavaVersion.VERSION_1_8.toString()
javaParameters = true
allWarningsAsErrors = false
}
incremental = true
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}
tasks.named<AbstractCompile>("compileGroovy") {
// Groovy only needs the declared dependencies
// (and not longer the output of compileJava)
classpath = sourceSets.main.get().compileClasspath
}
tasks.named<AbstractCompile>("compileKotlin") {
// Java also depends on the result of Groovy compilation
// (which automatically makes it depend of compileGroovy)
classpath += files(sourceSets.main.get().withConvention(GroovySourceSet::class) { groovy }.classesDirectory)
}
java {
sourceCompatibility = JavaVersion.VERSION_1_9
targetCompatibility = JavaVersion.VERSION_1_9
withJavadocJar()
withSourcesJar()
}
gradlePlugin {
plugins {
register("gradle-plugin") {
id = "com.dimaslanjaka"
implementationClass = "com.dimaslanjaka.gradle.plugin.Core"
}
}
}
// publishing
pluginBundle {
website = "https://github.com/dimaslanjaka/gradle-plugin"
vcsUrl = "https://github.com/dimaslanjaka/gradle-plugin"
description = project.description
(plugins) {
"gradle-plugin" {
displayName = project.name
description = project.description
tags = listOf("offline", "auto", "optimize", "performance")
version = project.version as String
}
}
mavenCoordinates {
groupId = "com.dimaslanjaka"
artifactId = "gradle-plugin"
version = project.version as String
}
}
val groovydoc: Groovydoc by tasks
val javadoc: Javadoc by tasks
val jar: Jar by tasks
jar.doLast {
// TODO: create jar without version
val jarnoversion = File(jar.archiveFile.get().asFile.parent, "gradle-plugin.jar")
jar.archiveFile.get().asFile.copyTo(jarnoversion, true)
}
// compile jar with dependencies
offlineLib.listFiles()?.forEach { offlineJar ->
offlineJar?.let { fileJar ->
if (fileJar.name.contains("sources")) {
// TODO: aggregating documentation groovy
groovydoc.apply {
source(zipTree(fileJar))
include("**/*.groovy")
}
// TODO: aggregating documentation java
javadoc.apply {
source(zipTree(fileJar))
include("**/*.java")
(options as StandardJavadocDocletOptions).apply {
if (JavaVersion.current().isJava9Compatible) {
addBooleanOption("html5", true)
} else {
addBooleanOption("html4", true)
}
if (JavaVersion.current().isJava8Compatible) {
addStringOption("Xdoclint:none", "-quiet")
}
}
}
} else if (!fileJar.name.contains("doc")) {
// TODO: aggregating jar source, skip documentation and sources
jar.from(zipTree(fileJar)) {
include("**")
exclude("META-INF", "META-INF/**")
}
}
}
}
tasks.findByName("publishPlugins")?.doLast {
updateVersionPref(project)
}
@Suppress("UNUSED_VARIABLE", "unused")
tasks {
val fatJar by creating(Jar::class) {
description = "create jar with dependencies"
isZip64 = true
group = "build"
// set output file
archiveFileName.set("gradle-plugin-wd.jar")
//destinationDirectory.set(File(project.rootDir, "../javafx/libs").absoluteFile)
// set manifest jar
manifest.attributes.apply {
put("Main-Class", "com.dimaslanjaka.gradle.plugin.Core")
put("Implementation-Title", "Gradle Kotlin DSL (${project.name})")
put("Implementation-Version", archiveVersion.get())
}
excludes.add("META-INF/**")
from(configurations.compileClasspath.map { config ->
config.map { mapit ->
if (mapit.isDirectory) {
mapit
} else {
zipTree(mapit)
}
}
}) {
exclude("META-INF", "META-INF/**")
}
with(jar.get())
dependsOn(jar)
}
val updateVersion by creating(Task::class) {
group = "project"
description = "Increase Version Manual"
doLast {
updateVersionPref(project)
}
}
val clearCacheTest by creating(Task::class) {
group = "project"
description = "clear all IDE configuration and Gradle Cache from tests project folders"
doLast {
listOf(
File(project.rootDir.absolutePath, "Test"),
File(project.rootDir.absolutePath, "repo/components/Test")
).forEach { testFolder ->
testFolder.listFiles()?.forEach { file ->
if (file.isDirectory) {
file.listFiles()?.forEach { testUnit ->
if (testUnit.isDirectory) {
listOf(".gradle", ".idea").map {
if (testUnit.name == it) {
if (testUnit.deleteRecursively()) {
println(testUnit.absolutePath + " Deleted Successfully")
}
}
}
}
}
}
}
}
}
}
}
//jar.dependsOn("fatJar")
fun updateVersionPref(project: Project) {
println("Updating version")
// TODO: auto update version after publish plugin
val v = getVersionPref(project)["version"].toString()
val token = v.split(".").map { it.toInt() } as MutableList
// increase minor
token[2] = token[2] + 1
// if minor has max value, increase major
if (token[2] >= Int.MAX_VALUE) {
token[1] = token[1] + 1
token[2] = 0
}
// if major has max value, increase main
if (token[1] >= Int.MAX_VALUE) {
token[0] = token[0] + 1
token[1] = 0
}
// apply version
getVersionPref(project)["version"] = token.joinToString(".")
project.version = token.joinToString(".")
// save new version
getVersionPref(project, token.joinToString("."))
val map = mutableMapOf<String, Any>()
map["main"] = token[0]
map["major"] = token[1]
map["minor"] = token[2]
map["version"] = token
//println(map)
println("Updated version to ${map["version"]}")
}
fun getVersionPref(project: Project, newVersion: String? = null): Properties {
// TODO: Set result properties
val fileVersion = File(project.projectDir, "version.properties")
if (!fileVersion.exists()) fileVersion.createNewFile()
val reader = FileReader(fileVersion)
val properties = Properties()
properties.load(reader)
if (!properties.containsKey("version") || (newVersion != null && newVersion.isNotEmpty())) {
// TODO: if newVersion is not null or properties not have version property, set and save them
properties["version"] = newVersion ?: "1.0.0"
properties.store(FileWriter(fileVersion), "Gradle Plugin Version")
println("Version Updated Successfully")
}
return properties
}
fun isSameFileSize(file1: File, file2: File): Boolean {
return if (!file1.exists() || !file2.exists()) {
false
} else {
file1.length().compareTo(file2.length()) == 0
}
}