forked from apache/grails-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
261 lines (230 loc) · 11.6 KB
/
Copy pathbuild.gradle
File metadata and controls
261 lines (230 loc) · 11.6 KB
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
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.grails.gradle.tasks.bom.ExtractDependenciesTask
import org.apache.grails.gradle.tasks.bom.ExtractedDependencyConstraint
import org.apache.grails.gradle.tasks.bom.PropertyNameCalculator
buildscript {
apply from: rootProject.layout.projectDirectory.file('dependencies.gradle')
}
plugins {
id 'java-platform'
id 'org.apache.grails.buildsrc.publish'
id 'org.apache.grails.buildsrc.sbom'
}
version = projectVersion
group = 'org.apache.grails'
javaPlatform {
allowDependencies()
}
ext {
isReleaseBuild = System.getenv('GRAILS_PUBLISH_RELEASE') == 'true'
isPublishedExternal = System.getenv().containsKey('NEXUS_PUBLISH_STAGING_PROFILE_ID')
// TODO: It should be possible to pull these build names using includedBuild, but I haven't found a way to do so
gradleBuildProjects = [
'grails-gradle-plugins':'org.apache.grails',
'grails-gradle-model':'org.apache.grails.gradle',
'grails-gradle-common':'org.apache.grails.gradle',
'grails-gradle-tasks':'org.apache.grails',
]
}
// Register the Micronaut platform in combinedPlatforms/combinedVersions so
// PropertyNameCalculator (used by extractConstraints and pomCustomization) can
// resolve a property name for the micronaut-platform constraint.
project.ext.combinedPlatforms = combinedPlatforms + ['micronaut-platform': "io.micronaut.platform:micronaut-platform:$micronautPlatformVersion".toString()]
project.ext.combinedVersions = combinedVersions + ['micronaut-platform.version': micronautPlatformVersion as String]
// Coordinates we override via customBomDependencies — these must be excluded from the
// inherited platform chain so they don't conflict with our strictly-versioned overrides
// when consumers apply this BOM via enforcedPlatform.
def overriddenModules = customBomDependencies.values().collect { String coord ->
def parts = coord.split(':')
[group: parts[0], module: parts[1]]
}
Set<String> overriddenCoords = overriddenModules.collect { "${it.group}:${it.module}".toString() } as Set
dependencies {
api(platform(project(':grails-base-bom'))) {
overriddenModules.each { ovr ->
exclude group: ovr.group, module: ovr.module
}
}
// Re-export the Micronaut platform so consumers of grails-micronaut-bom inherit Micronaut's
// managed versions transitively and don't need to declare the platform themselves.
// Exclude Groovy since we declare the required version explicitly below via customBomDependencies.
// Exclude Spock since the base BOM manages that version.
// Exclude Jackson 3 (tools.jackson) since spring-boot-dependencies manages that version
// and the two platforms routinely disagree on the patch (e.g. SB 4.0.6 ships
// jackson-bom 3.1.2 while micronaut-platform 5.0.0 pins 3.1.3). Let Spring Boot
// remain the single source of truth so the dependency-version validator does not
// see drift between probe and project resolution.
api(platform("io.micronaut.platform:micronaut-platform:$micronautPlatformVersion")) {
exclude group: 'org.apache.groovy'
exclude group: 'org.spockframework'
exclude group: 'tools.jackson'
}
constraints {
// Re-declare base BOM constraints directly so enforcedPlatform() consumers
// get forced versions. Constraints inherited via platform() are not enforced
// by enforcedPlatform — only direct constraints are.
// Skip entries we override below in customBomDependencies to avoid conflicting
// strictly constraints under enforcedPlatform.
gradleBomDependencies.values().each { String coord ->
def parts = coord.split(':')
String key = parts[0] + ':' + parts[1]
if (key in overriddenCoords) {
return
}
api coord
}
bomDependencies.values().each { String coord ->
def parts = coord.split(':')
String key = parts[0] + ':' + parts[1]
if (key in overriddenCoords) return
api coord
}
for (def entry : bomPlatformDependencies.entrySet()) {
api entry.value
}
// Re-declare the Micronaut platform as a constraint for enforcedPlatform support
api "io.micronaut.platform:micronaut-platform:$micronautPlatformVersion"
for (def entry : customBomDependencies.entrySet()) {
def parts = entry.value.split(':')
if (parts.length == 3) {
api("${parts[0]}:${parts[1]}") {
version {
strictly parts[2]
}
}
} else {
api entry.value
}
}
}
}
configurations.register('bomDependencies').configure {
it.canBeResolved = true
it.transitive = true
it.extendsFrom(configurations.named('api').get())
}
tasks.register('extractConstraints', ExtractDependenciesTask).configure { ExtractDependenciesTask it ->
it.captureProjectServices(project.dependencies, project.configurations)
it.configuration = configurations.named('bomDependencies')
it.configurationName = 'bomDependencies'
it.destination = project.layout.buildDirectory.file('grails-micronaut-bom-constraints.adoc')
it.platformDefinitions = combinedPlatforms
it.definitions = combinedDependencies
it.projectName = project.name
it.versions = combinedVersions
// Micronaut's platform imports many sub-BOMs (micronaut-*-bom, netty-bom, etc.) that are
// not explicitly registered in dependencies.gradle. Auto-register them so extractConstraints
// can document their versions without requiring manual entries for every transitive platform.
// this is required because the micronaut bom format uses gradle modules instead of a pom like spring boot
it.autoRegisterTransitivePlatforms = true
rootProject.subprojects.each { p ->
evaluationDependsOn(p.path)
}
it.projectArtifactIds.set(project.provider {
Map<String, String> artifactIdMappings = [:]
rootProject.subprojects.each { p ->
artifactIdMappings[p.name] = p.findProperty('pomArtifactId') ?: p.name
}
for (Map.Entry<String, String> dependency : project.ext.gradleBuildProjects.entrySet()) {
artifactIdMappings[dependency.key] = dependency.key
}
artifactIdMappings
})
it.forcedGroupPrefixes.set(['org.apache.grails.profiles': 'grails-profile'])
it.projectCoordinateProperties.set(project.provider {
Map<String, String> projectCoordinates = [:]
rootProject.subprojects.each { p ->
String artifactId = p.findProperty('pomArtifactId') as String ?: p.name
String baseVersionName = artifactId.replaceAll('[.]', '-')
projectCoordinates["${p.group}:${ artifactId}:${p.version}" as String] = baseVersionName
}
for (Map.Entry<String, String> dependency : project.ext.gradleBuildProjects.entrySet()) {
projectCoordinates["${dependency.value}:${dependency.key}:${project.version}" as String] = dependency.key
}
projectCoordinates
})
it.dependsOn(project.tasks.named('generateMetadataFileForMavenPublication'), project.tasks.named('generatePomFileForMavenPublication'))
}
def validateNoSnapshotDependencies = tasks.register('validateNoSnapshotDependencies')
validateNoSnapshotDependencies.configure { Task it ->
it.group = 'publishing'
it.description = 'Validates that no snapshot dependencies are present in the project when performing a release.'
it.doLast {
configurations.each { config ->
config.allDependencies.each { dep ->
if (dep.version && dep.version.contains('-SNAPSHOT')) {
throw new GradleException("Releases cannot have a snapshot dependency: ${dep.group}:${dep.name} (${dep.version})")
}
}
}
}
}
if (ext.isReleaseBuild && ext.isPublishedExternal) {
project.afterEvaluate {
tasks.named('generateMetadataFileForMavenPublication').configure {
dependsOn(validateNoSnapshotDependencies)
}
tasks.named('generatePomFileForMavenPublication').configure {
dependsOn(validateNoSnapshotDependencies)
}
}
}
ext {
pomDescription = 'Grails Micronaut BOM (Bill of Materials) for Grails projects integrating with Micronaut. Layers Micronaut-specific dependency overrides on top of grails-bom; consume as enforcedPlatform.'
pomCustomization = { xml ->
def root = xml.asNode()
def propertiesNode = root.properties ? root.properties[0] : root.appendNode('properties')
def depMgmt = root.dependencyManagement?.getAt(0)
def deps = depMgmt?.dependencies?.getAt(0)
if (deps) {
PropertyNameCalculator propertyNameCalculator = new PropertyNameCalculator(combinedPlatforms, combinedDependencies, combinedVersions)
propertyNameCalculator.addForcedGroupPrefix('org.apache.grails.profiles', 'grails-profile')
propertyNameCalculator.addProjects(rootProject.subprojects)
for (String gradleArtifactId : project.ext.gradleBuildProjects) {
propertyNameCalculator.addProject('org.apache.grails.gradle', gradleArtifactId, project.version as String, gradleArtifactId)
}
Map<String, String> pomProperties = [:]
deps.dependency.each { dep ->
String groupId = dep.groupId.text().trim()
String artifactId = dep.artifactId.text().trim()
boolean isBom = dep.scope.text().trim() == 'import'
String inlineVersion = dep.version.text().trim()
if (inlineVersion == 'null') {
inlineVersion = null
}
if (inlineVersion) {
ExtractedDependencyConstraint extractedConstraint = propertyNameCalculator.calculate(groupId, artifactId, inlineVersion, isBom)
if (extractedConstraint?.versionPropertyReference) {
// use the property reference instead of the hard coded version so that it can be
// overriden by the spring boot dependency management plugin
dep.version[0].value = extractedConstraint.versionPropertyReference
// Add an entry in the <properties> node with the actual version number
pomProperties.put(extractedConstraint.versionPropertyName, inlineVersion)
}
} else if (!inlineVersion) {
throw new GradleException("Dependency $groupId:$artifactId does not have a version.")
}
}
for (Map.Entry<String, String> property : pomProperties.entrySet()) {
propertiesNode.appendNode(property.key, property.value)
}
}
}
}