generated from remal/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
113 lines (91 loc) · 4.03 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
import org.gradle.util.GradleVersion
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
buildscript {
String rootGroupId = project.ext.rootGroupId = "name.remal.gradle-plugins.${rootProject.name}"
String rootArtifactId = project.ext.rootArtifactId = rootProject.name
String rootSnapshotVersion = project.ext.rootSnapshotVersion = '1-SNAPSHOT'
dependencies {
//classpath("$rootGroupId:$rootArtifactId:$rootSnapshotVersion") { version { strictly(rootSnapshotVersion) } }
classpath 'name.remal.gradle-plugins.toolkit:build-logic:0.70.4'
}
repositories {
mavenCentral()
gradlePluginPortal()
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
allprojects {
group = project.rootGroupId
version = project.rootSnapshotVersion
}
apply plugin: 'name.remal.toolkit.build-logic'
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
apply plugin: 'java-gradle-plugin'
dependencies {
}
gradlePlugin {
plugins {
'name.remal.template-plugin' {
id = 'name.remal.template-plugin'
implementationClass = 'name.remal.gradle_plugins.template.TemplatePlugin'
displayName = 'Template plugin'
description = property('repository-description')
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* TODO: REMOVE THIS SECTION FOR REAL PLUGIN */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
if (project.isRunningOnCi) {
TaskProvider validateRepositoryProperties = tasks.register('validateRepositoryProperties') {
outputs.upToDateWhen { false }
doLast {
String rootProjectName = project.rootProject.name
String repositoryName = project.ext['repository-name']
if (rootProjectName != repositoryName) {
throw new GradleException("Root project name ('$rootProjectName') does NOT equal to the repository name: '$repositoryName'")
}
}
}
tasks.named('check').configure {
dependsOn(validateRepositoryProperties)
}
TaskProvider processGradleProperties = tasks.register('processGradleProperties') {
outputs.upToDateWhen { false }
doLast {
String repositoryName = project.ext['repository-name'] ?: ''
if (repositoryName.isEmpty()) {
throw new GradleException("`repository-name` property is empty")
}
if (repositoryName != 'template') {
throw new GradleException("This code should be executed for template repository only")
}
File file = project.file('gradle.properties')
Properties currentProperties = new Properties()
file.withReader('UTF-8') { currentProperties.load(it) }
String content = file.getText('UTF-8')
Map<String, String> handledProperties = [:]
content = content.replaceFirst(/((?:^|[\r\n]\s*)(gradle-api.min-version))\s*=\s*\d+\S*(\s|$)/) { List<String> groups ->
GradleVersion lastMinorVersion = project.getAllGradleVersions().findAll { GradleVersion ver ->
ver == ver.baseVersion && ver.version.count('.') == 1
}[1]
String value = lastMinorVersion.version
handledProperties[groups[2]] = value
return "${groups[1]} = ${value}${groups[3]}"
}
handledProperties.entrySet().removeIf { entry ->
String currentValue = currentProperties.getProperty(entry.key)
return currentValue == entry.value
}
handledProperties.keySet().forEach { key ->
println " Changing property: $key"
}
if (!handledProperties.isEmpty()) {
file.setText(content, 'UTF-8')
}
}
}
tasks.named('processReadme').configure {
dependsOn(processGradleProperties)
}
}