-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
251 lines (220 loc) · 7.71 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
239
240
241
242
243
244
245
246
247
248
249
250
251
import static java.lang.String.valueOf
subprojects {
apply plugin: 'maven-publish'
apply plugin: 'scala'
apply plugin: 'distribution'
apply plugin: 'java-library'
apply plugin: 'net.linguica.maven-settings'
apply plugin: "com.github.hierynomus.scalariform"
apply plugin: 'dataweave'
mavenSettings {
if (project.hasProperty('maven.settings.location')) {
userSettingsFileName = project.property('maven.settings.location')
}
}
def branch = gitBranch()
def release = branch.startsWith("release/")
ext {
if (release) {
// format is: release/{version}[/{weave-version}]
def branchParts = branch.split("/")
projectVersion = branchParts[1]
if (!gitTag(projectVersion).isEmpty()) {
throw new GradleException("Cannot release a tagged version")
}
if (branchParts.size() == 3) {
weaveVersion = branchParts[2]
}
if (isSnapshot(weaveVersion) || isSnapshot(projectVersion) || isSnapshot(weavedocVersion)) {
throw new GradleException("Cannot release with snapshot dependencies. \nWeaveVersion: " + weaveVersion + "\nVersion: " + projectVersion + "\nWeaveDocVersion: " + weavedocVersion)
}
} else if (!isSnapshot(projectVersion)) {
throw new GradleException("Cannot build non snapshot versions from a regular branch")
}
}
group = "org.mule.weave"
version = projectVersion
java {
withJavadocJar()
withSourcesJar()
}
javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
}
compileJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
compileScala {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
repositories {
// if(Boolean.getBoolean("mavenLocal")) {
// mavenLocal()
// }
mavenCentral()
maven {
name "mule-releases"
url "https://repository.mulesoft.org/nexus/content/repositories/releases/"
}
maven {
name "mule-snapshots"
url "https://repository.mulesoft.org/nexus/content/repositories/snapshots/"
}
maven {
name "jitpack"
url "https://jitpack.io"
}
}
dependencies {
implementation group: 'org.mule.weave', name: 'wlang', version: weaveVersion
implementation group: 'org.scala-lang', name: 'scala-library', version: scalaVersion
}
publishing {
publications.all {
pom.withXml {
asNode().dependencies.'*'.findAll() {
it.scope.text() == 'runtime' && project.configurations.implementation.allDependencies.find { dep ->
dep.name == it.artifactId.text()
}
}.each { it.scope*.value = 'compile' }
}
}
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
maven {
name "mule-ee-releases"
url "https://repository-master.mulesoft.org/nexus/content/repositories/${project.version.endsWith('-SNAPSHOT') ? 'snapshots/' : 'releases/'}"
}
}
}
jar {
def moduleName = "$project.group.${moduleNameSanitizer(project.name)}"
println("Module: " + moduleName)
manifest {
attributes 'Automatic-Module-Name': moduleName
}
into("META-INF/maven/$project.group/$project.name") {
from "$project.buildDir/publications/mavenJava"
include "*.pom"
include "*.xml"
}
into("META-INF/maven/$project.group/$project.name") {
from "$project.buildDir/publications/mavenJava"
include "*.properties"
}
}
scalariform {
alignSingleLineCaseStatements = true
doubleIndentClassDeclaration = true
placeScaladocAsterisksBeneathSecondAsterisk = true
}
project.afterEvaluate {
project.tasks.matching { it.name == 'generatePomFileForMavenJavaPublication' }.all {
it.dependsOn 'pomProperties'
}
project.tasks.jar.dependsOn 'generatePomFileForMavenJavaPublication'
}
task pomProperties() {
Properties props = new Properties();
File propertiesFile = new File("$project.buildDir/publications/mavenJava/pom.properties")
if (!propertiesFile.exists()) {
propertiesFile.getParentFile().mkdirs()
propertiesFile.createNewFile()
}
props.load(propertiesFile.newDataInputStream())
props.setProperty('version', valueOf(project.version))
props.setProperty('groupId', valueOf(project.group))
props.setProperty('artifactId', project.name)
props.store(propertiesFile.newWriter(), null)
}
dataweave {
template = "markdown,assciidoc"
}
task docs(dependsOn: weavedoc, type: Zip) {
archiveClassifier = "weavedocs"
from 'build/docs/weavedocs/'
}
compileScala.dependsOn(formatScala)
build.dependsOn("weavedoc")
}
def isSnapshot(String version) {
version.endsWith("-SNAPSHOT")
}
def gitBranch() {
def ciBranch = System.getenv("BRANCH_NAME")
if (ciBranch != null) {
ciBranch
} else {
def workingDir = new File("${project.projectDir}/")
def branch = ""
def proc = "git rev-parse --abbrev-ref HEAD".execute(null, workingDir)
proc.in.eachLine { line -> branch = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
branch
}
}
def gitTag(String version) {
def workingDir = new File("${project.projectDir}/")
def tag = ""
def fetch = "git fetch --tags".execute(null, workingDir)
fetch.waitFor()
// format is: {dw-version} but used to be {dw-version}-release
def escapedVersion = version.replaceAll("\\.", "\\\\.")
def grep = "git tag --list | grep '" + escapedVersion + "-release\\|" + escapedVersion + "\$'"
def proc = ['bash', '-c', grep].execute(null, workingDir)
proc.in.eachLine { line -> tag = line }
proc.err.eachLine { line -> println line }
proc.waitFor()
tag
}
static String moduleNameSanitizer(String name) {
def replaced = name.replaceAll("-", ".")
def parts = replaced.split("\\.")
if (parts.length > 1) {
String last = parts[parts.length - 1]
// Replace 'modules' by 'module'
if ("modules".equalsIgnoreCase(last)) {
last = "module"
}
// If ends with 'module' reorder parts
if ("module".equalsIgnoreCase(last)) {
for (int i = parts.length - 2 ; i >= 0 ; i--) {
def part = parts[i]
parts[i + 1] = part
}
parts[0] = last
}
}
def joined = String.join(".", parts)
joined
}
buildscript {
repositories {
maven {
name "mule-releases"
url "https://repository.mulesoft.org/nexus/content/repositories/releases/"
}
maven {
name "mule-snapshots"
url "https://repository.mulesoft.org/nexus/content/repositories/snapshots/"
}
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'net.linguica.gradle:maven-settings-plugin:0.5', {
exclude module: "sisu-guava"
}
classpath "gradle.plugin.com.hierynomus.gradle.plugins:scalariform-gradle-plugin:0.4.0"
classpath "org.mule.weave:weave-gradle-plugin:" + weavedocVersion
}
}