forked from micronaut-projects/micronaut-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
134 lines (113 loc) · 3.84 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
plugins {
id 'java'
id 'java-library'
}
repositories {
mavenCentral()
//TODO remove
jcenter()
maven { url "https://repo.grails.org/grails/libs-releases" }
}
boolean micronautSnapshot = rootProject.version.toString().endsWith("-SNAPSHOT")
def excludedProjects = [
"benchmarks",
"inject-test-utils",
"test-suite",
"test-suite-groovy",
"test-suite-helper",
"test-suite-kotlin",
"test-utils"
]
configurations.all {
resolutionStrategy.dependencySubstitution {
for (Project p : rootProject.subprojects) {
if (!p.subprojects.empty) continue
if (excludedProjects.contains(p.name)) continue
substitute module("io.micronaut:micronaut-$p.name") with project(":$p.name")
}
}
}
dependencies {
//Include Micronaut BOM
implementation enforcedPlatform(project(":bom"))
//Include other BOMs
for (dep in bomVersions) {
def info = dep.value
def versionExpr = info.version
implementation platform("$info.group:$info.name:$versionExpr")
}
//Include core projects
for (Project p : rootProject.subprojects) {
if (!p.subprojects.empty) continue
if (p.name.contains("bom") || p.name.contains("parent")) continue
if (excludedProjects.contains(p.name)) continue
implementation p
}
//Include the rest of dependencies
for (dep in dependencyVersions) {
def info = dep.value
// don't include snapshots
if (info.version.toString().endsWith("-SNAPSHOT") && !micronautSnapshot) {
continue
}
def versionExpr = dep.value.version
if (info.name) {
implementation "$info.group:$info.name:$versionExpr"
}
if (info.modules) {
for (m in info.modules) {
implementation "$info.group:$m:$versionExpr"
}
}
}
}
//publishing {
// publications {
// maven(MavenPublication) {
// groupId = 'io.micronaut.internal'
// artifactId = 'micronaut-bom-check'
// version = project.version
// from components.java
// }
// }
//}
//publish.enabled = false
task validateMicronautBom {
doLast {
configurations.each { cfg ->
if (cfg.isCanBeResolved()) {
cfg.resolve()
}
}
}
}
task validateThirdPartyBoms(dependsOn:['validateMicronautBom']) {
doLast {
for (dep in bomVersions) {
def info = dep.value
if (info.group.startsWith("io.micronaut")) continue
def componentId = "$info.group:$info.name:$info.version"
Configuration cfg = configurations.detachedConfiguration(dependencies.create(componentId))
cfg.incoming.resolutionResult.allDependencies { DependencyResult dr ->
def result = dependencies.createArtifactResolutionQuery()
.forModule(info.group, info.name, info.version)
.withArtifacts(MavenModule, MavenPomArtifact)
.execute()
for (component in result.resolvedComponents) {
component.getArtifacts(MavenPomArtifact).each {
def pom = new XmlSlurper().parse(it.file)
pom.dependencyManagement.dependencies.dependency.each {
String groupId = it.groupId.text()
groupId = groupId.replace('${project.groupId}', info.group)
if (!groupId.startsWith(info.group)) {
throw new GradleException("Error validating BOM [${componentId}]: includes the dependency [${it.groupId}:${it.artifactId}:${it.version}] that doesn't belong to the group id of the BOM: [${info.group}]")
}
}
}
}
}
}
}
}
task bomCheck(dependsOn: [validateThirdPartyBoms])
check.dependsOn(bomCheck)