4
4
*/
5
5
// file:noinspection VulnerableLibrariesLocal
6
6
// file:noinspection SpellCheckingInspection
7
+ buildscript {
8
+ repositories {
9
+ // Use Maven Central for resolving dependencies.
10
+ mavenCentral()
11
+ }
12
+ dependencies {
13
+ classpath ' org.yaml:snakeyaml:2.0'
14
+ }
15
+ }
7
16
8
17
plugins {
9
18
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
@@ -24,19 +33,58 @@ repositories {
24
33
mavenCentral()
25
34
}
26
35
27
- def props = new Properties ()
28
- props. load(new FileInputStream (rootProject. file(" gradle.properties" )))
29
- def _name = props. getProperty(" ng.name" )
30
- def _version = props. getProperty(" ng.version" )
36
+ import org.yaml.snakeyaml.Yaml
37
+
38
+ class JarConfig {
39
+ boolean enabled
40
+ String source
41
+
42
+ JarConfig (Map<String , Object > config ) {
43
+ enabled = config[' enabled' ] ?: false
44
+ source = config[' source' ] ?: ' '
45
+ }
46
+ }
47
+
48
+ class NgConfig {
49
+ String name
50
+ String version
51
+ boolean enabledLink
52
+ List<JarConfig > jars
53
+
54
+ @SuppressWarnings (' GroovyAssignabilityCheck' )
55
+ NgConfig (Map<String , Object > configs ) {
56
+ name = configs. containsKey(' name' ) ? configs[' name' ] : ' bot4j'
57
+ version = configs. containsKey(' version' ) ? configs[' version' ] : ' v0.0.0'
58
+ enabledLink = configs. containsKey(' enabled_link' ) ? configs[' enabled_link' ] : false
59
+ // jars = configs.containsKey('jars') ? configs['jars'] : [] // List<String> jars
60
+ jars = configs. containsKey(' jars' ) ? configs[' jars' ]. collect { new JarConfig (it) } : []
61
+ }
62
+ }
63
+
64
+ // Define ngConfig as a static global variable
65
+ NgConfig ngConfig = loadNgConfig()
66
+
67
+ NgConfig loadNgConfig () {
68
+ def configs = file(' gradle.yml' )
69
+ if (configs. exists()) {
70
+ def yaml = new Yaml ()
71
+ def config = yaml. load(new FileInputStream (configs))
72
+ println ' ⌛ Loading NgConfigs configuration via gradle.yml'
73
+ return new NgConfig (config[' ng' ] as Map<String , Object > )
74
+ } else {
75
+ println ' ⚠️ gradle.yml not found, using default configuration'
76
+ return new NgConfig (new HashMap<String , Object > ())
77
+ }
78
+ }
31
79
32
80
// Define a task to build the Groovy library into a JAR
33
81
tasks. register(' buildGroovyJar' , Jar ) {
34
82
// Set the base directory for the source files
35
83
from ' src/main/groovy'
36
84
// Set the destination directory for the compiled classes
37
85
into(' ' )
38
- archiveFileName = " ${ _name } " + " .jar"
39
- version(" ${ _version } " )
86
+ archiveFileName = " ${ ngConfig.getName() } " + " .jar"
87
+ version(" ${ ngConfig.getVersion() } " )
40
88
include ' **/*.groovy'
41
89
}
42
90
@@ -46,12 +94,39 @@ tasks.named('build') {
46
94
}
47
95
48
96
tasks. jar {
49
- archivesBaseName = " ${ _name} "
50
- version = " ${ _version} "
97
+ archivesBaseName = " ${ ngConfig.getName()} "
98
+ version = " ${ ngConfig.getVersion()} "
99
+
100
+ // Handle duplicates
101
+ // duplicatesStrategy = DuplicatesStrategy.EXCLUDE
102
+ // Compressing the external JAR files listed in gradle.yml using zipTree if enabled_link is true
103
+ if (ngConfig. isEnabledLink() && ! ngConfig. getJars(). isEmpty()) {
104
+ ngConfig. getJars(). each { jar ->
105
+ if (jar. isEnabled() && ! jar. getSource(). isEmpty()) {
106
+ println (" 📦 Jar compressing... [${ jar.getSource()} ]" )
107
+ from {
108
+ zipTree(file(jar. getSource()))
109
+ }
110
+ }
111
+ }
112
+ } else {
113
+ println ' ⚠️ Skipping compression of dependency JAR files...'
114
+ }
51
115
}
52
116
53
117
// Add dependencies
54
118
dependencies {
119
+ // Add the dependencies listed in the gradle.yml file
120
+ if (! ngConfig. getJars(). isEmpty()) {
121
+ ngConfig. getJars(). each { jar ->
122
+ if (! jar. getSource(). isEmpty()) {
123
+ println (" 🔄 Jar mounting... [${ jar.getSource()} ]" )
124
+ implementation files(jar. getSource())
125
+ }
126
+ }
127
+ } else {
128
+ println ' ⚠️ No JAR files specified in gradle.yml for dependencies.'
129
+ }
55
130
// Use the awesome Spock testing and specification framework
56
131
testImplementation libs. spock. core
57
132
// Incorporate JUnit Jupiter API version 4.13.2 for unit testing,
0 commit comments