generated from ortus-boxlang/boxlang-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
278 lines (252 loc) · 8.43 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
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
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_packaging
plugins {
id 'java'
// For source code formatting
id "com.diffplug.spotless" version "6.25.0"
// https://github.com/harbby/gradle-serviceloader
id "com.github.harbby.gradle.serviceloader" version "1.1.8"
// For building shadow jars with jdk 17 ONLY
//id 'com.github.johnrengelman.shadow' version '8.1.1'
// For building shadow jars using JDK 21 +, they had to fork
id "io.github.goooler.shadow" version "8.1.8"
// Download task
id "de.undercouch.download" version "5.6.0"
}
/**
* Project Properties
*/
sourceCompatibility = jdkVersion
targetCompatibility = jdkVersion
ext {
buildID = System.getenv( 'BUILD_ID' ) ?: '0'
branch = System.getenv( 'BRANCH' ) ?: 'development'
}
if ( branch == 'development' ) {
// If the branch is 'development', ensure the version ends with '-snapshot'
// This replaces any existing prerelease identifier with '-snapshot'
version = version.contains('-') ? version.replaceAll(/-.*/, '-snapshot') : "${version}-snapshot"
boxlangVersion = boxlangVersion.contains('-') ? boxlangVersion.replaceAll(/-.*/, '-snapshot') : "${boxlangVersion}-snapshot"
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
// Until BoxLang is published to Maven Central
// Look for it in the local build directory
// You must run `./gradle build -x test` in the BoxLang project
compileOnly files( '../../boxlang/build/distributions/boxlang-' + boxlangVersion + '-all.jar' )
implementation files( '../../boxlang-web-support/build/distributions/boxlang-web-support-' + boxlangVersion + '.jar' )
// Downloaded Dependencies
compileOnly files( 'src/test/resources/libs/boxlang-' + boxlangVersion + '-all.jar' )
implementation files( 'src/test/resources/libs/boxlang-web-support-' + boxlangVersion + '.jar' )
// Testing Dependencies
testImplementation files( '../../boxlang/build/distributions/boxlang-' + boxlangVersion + '-all.jar' )
testImplementation files( '../../boxlang-web-support/build/distributions/boxlang-web-support-' + boxlangVersion + '.jar' )
testImplementation files( 'src/test/resources/libs/boxlang-' + boxlangVersion + '-all.jar' )
testImplementation files( 'src/test/resources/libs/boxlang-web-support-' + boxlangVersion + '.jar' )
testImplementation "org.junit.jupiter:junit-jupiter:5.+"
testImplementation "org.mockito:mockito-core:5.+"
testImplementation "com.google.truth:truth:1.+"
}
java {
// Produces a javadocs jar
withJavadocJar()
}
compileJava {
// Compiler Options
options.incremental = true
options.encoding = 'UTF-8'
options.debug()
}
compileTestJava{
// Make sure the service loaders are created before testing
dependsOn compileJava, serviceLoaderBuild
}
compileTestJava.finalizedBy( shadowJar )
/**
* Clean up
*/
clean {
doLast{
var userDir = file( "${System.getProperty('user.home')}/.boxlang/classes" )
if ( userDir.exists() ) {
userDir.deleteDir()
println "+ Cleared user home classes " + userDir.toString()
}
println "+ Clean finalized!"
}
}
javadoc {
// To avoid our own doclet issues
options.addBooleanOption( "Xdoclint:none", true )
//exclude '**/boxlang/parser/**'
options.addBooleanOption( 'html5', true )
}
task zipJavadocs( type: Zip ) {
group "documentation"
from javadoc.destinationDir
archiveFileName = "${project.name}-javadocs-${version}.zip"
destinationDirectory = file( "$buildDir/distributions" )
// Output that the docs have been zippped
doLast {
println "+ Javadocs have been zipped to the distribution folder"
}
}
javadoc.finalizedBy( zipJavadocs )
/**
* Docs are here:
* - https://github.com/harbby/gradle-serviceloader,
* - https://plugins.gradle.org/plugin/com.github.harbby.gradle.serviceloader
* This generates the META-INF/services files for the ServiceLoader as part of the `build` task
*/
serviceLoader {
serviceInterface 'ortus.boxlang.runtime.bifs.BIF'
serviceInterface 'ortus.boxlang.runtime.components.Component'
serviceInterface 'ortus.boxlang.runtime.async.tasks.IScheduler'
serviceInterface 'ortus.boxlang.runtime.cache.providers.ICacheProvider'
serviceInterface 'ortus.boxlang.runtime.events.IInterceptor'
}
jar {
archiveVersion = "${version}"
manifest {
attributes 'Description': 'ExampleBoxLangModule'
}
}
shadowJar {
mergeServiceFiles()
destinationDirectory = file( "build/libs" )
}
build.finalizedBy( shadowJar )
/**
* Source Code Formatting
*/
spotless {
java {
target fileTree( "." ) {
include "**/*.java"
exclude "**/build/**", "bin/**", "examples/**"
}
eclipse().configFile( "./.ortus-java-style.xml" )
toggleOffOn()
}
}
/**
* Custom task that creates a build/module folders
* - Copies the build/libs/BoxLangModuleTemplate-1.0.0-all.jar to build/module/libs/BoxLangModuleTemplate-1.0.0-all.jar
* - Copies the src/main/bx/** to build/module/ folder.
*/
task createModuleStructure(type: Copy) {
from( 'build/libs' ) {
include "${project.name}-${version}-all.jar"
into 'libs'
}
from( 'src/main/bx' ) {
include '**/*.bx'
// Token Replacements Go Here
filter{ line -> line.replaceAll( '@build.version@', project.version ) }
if( project.branch == "development" ){
filter{ line -> line.replaceAll( '\\+@build.number@', '-SNAPSHOT' ) }
} else {
filter{ line -> line.replaceAll( '@build.number@', project.buildID ) }
}
}
from( '.' ) {
include 'box.json'
include 'readme.md'
include 'changelog.md'
// Token Replacements Go Here
filter{ line -> line.replaceAll( '@build.version@', project.version ) }
if( project.branch == "development" ){
filter{ line -> line.replaceAll( '\\+@build.number@', '-SNAPSHOT' ) }
} else {
filter{ line -> line.replaceAll( '@build.number@', project.buildID ) }
}
}
destinationDir = file( 'build/module' )
}
task zipModuleStructure( type: Zip ) {
group "distribution"
from createModuleStructure.destinationDir
archiveFileName = "${project.name}-${version}.zip"
destinationDirectory = file( "$buildDir/distributions" )
// Output that the module has been zippped
doLast {
println "+ Module has been zipped to the distribution folder"
}
}
createModuleStructure.finalizedBy( zipModuleStructure )
shadowJar.finalizedBy( createModuleStructure )
test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
}
}
/**
* TEMPORARY until we publish to maven
* Task to download the latest jar from https://ortus-temp.s3.amazonaws.com/jericho/libs/boxlang-1.0.0-all.jar
*/
task downloadBoxLang( type: Download ) {
// Create the destination directory
doFirst {
file( "src/test/resources/libs" ).mkdirs()
}
// Configure the URL of the file to download
src([
"https://downloads.ortussolutions.com/ortussolutions/boxlang/${boxlangVersion}/boxlang-${boxlangVersion}-all.jar",
"https://downloads.ortussolutions.com/ortussolutions/boxlang-runtimes/boxlang-web-support/${boxlangVersion}/boxlang-web-support-${boxlangVersion}.jar"
])
// Specify the destination directory for the downloaded file
dest "src/test/resources/libs/"
overwrite true
onlyIfModified false
}
/**
* Project Wide Helper function
* This is not a task, but a reusable UDF
*/
project.ext.bumpVersion = { boolean major = false, boolean minor = false, boolean patch = false ->
def propertiesFile = file( './gradle.properties' );
def properties = new Properties();
properties.load( propertiesFile.newDataInputStream() )
def versionTarget = major ? 0 : minor ? 1 : 2
def currentVersion = properties.getProperty( 'version' )
def versionParts = currentVersion.split( '\\.' )
def newPathVersion = versionParts[ versionTarget ].toInteger() + 1
def newVersion = '';
if( patch ){
newVersion = "${versionParts[ 0 ]}.${versionParts[ 1 ]}.${newPathVersion}"
} else if( minor ){
newVersion = "${versionParts[ 0 ]}.${newPathVersion}.${versionParts[ 2 ]}"
} else if( major ){
newVersion = "${newPathVersion}.${versionParts[ 1 ]}.${versionParts[ 2 ]}"
}
properties.setProperty( 'version', newVersion )
properties.store( propertiesFile.newWriter(), null )
println "Bumped version from ${currentVersion} to ${newVersion}"
}
/**
* Bump the major version number
*/
task bumpMajorVersion {
doLast{
bumpVersion( true )
}
}
/**
* Bump the minor version number
*/
task bumpMinorVersion {
doLast{
bumpVersion( false, true )
}
}
/**
* Bump the patch version number
*/
task bumpPatchVersion {
doLast{
bumpVersion( false, false, true )
}
}