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,47 @@ 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 NgConfig {
39
+ String name
40
+ String version
41
+ boolean enabledLink
42
+ List<String > jars
43
+
44
+ @SuppressWarnings (' GroovyAssignabilityCheck' )
45
+ NgConfig (Map<String , Object > configs ) {
46
+ name = configs. containsKey(' name' ) ? configs[' name' ] : ' bot4j'
47
+ version = configs. containsKey(' version' ) ? configs[' version' ] : ' v1.0.0'
48
+ enabledLink = configs. containsKey(' enabled_link' ) ? configs[' enabled_link' ] : false
49
+ jars = configs. containsKey(' jars' ) ? configs[' jars' ] : []
50
+ }
51
+ }
52
+
53
+ // Define ngConfig as a static global variable
54
+ NgConfig ngConfig = loadNgConfig()
55
+
56
+ NgConfig loadNgConfig () {
57
+ def configs = file(' gradle.yml' )
58
+ if (configs. exists()) {
59
+ def yaml = new Yaml ()
60
+ def config = yaml. load(new FileInputStream (configs))
61
+ println ' ⌛ Loading NgConfigs configuration via gradle.yml'
62
+ return new NgConfig (config[' ng' ] as Map<String , Object > )
63
+ } else {
64
+ println ' ⚠️ gradle.yml not found, using default configuration'
65
+ return new NgConfig (new HashMap<String , Object > ())
66
+ }
67
+ }
31
68
32
69
// Define a task to build the Groovy library into a JAR
33
70
tasks. register(' buildGroovyJar' , Jar ) {
34
71
// Set the base directory for the source files
35
72
from ' src/main/groovy'
36
73
// Set the destination directory for the compiled classes
37
74
into(' ' )
38
- archiveFileName = " ${ _name } " + " .jar"
39
- version(" ${ _version } " )
75
+ archiveFileName = " ${ ngConfig.getName() } " + " .jar"
76
+ version(" ${ ngConfig.getVersion() } " )
40
77
include ' **/*.groovy'
41
78
}
42
79
@@ -46,12 +83,37 @@ tasks.named('build') {
46
83
}
47
84
48
85
tasks. jar {
49
- archivesBaseName = " ${ _name} "
50
- version = " ${ _version} "
86
+ archivesBaseName = " ${ ngConfig.getName()} "
87
+ version = " ${ ngConfig.getVersion()} "
88
+
89
+ // Handle duplicates
90
+ // <code>
91
+ // duplicatesStrategy = DuplicatesStrategy.EXCLUDE
92
+ // </code>
93
+ // Compressing the external JAR files listed in gradle.yml using zipTree if enabled_link is true
94
+ if (ngConfig. isEnabledLink() && ! ngConfig. getJars(). isEmpty()) {
95
+ ngConfig. getJars(). each { jar ->
96
+ println (" 📦 Jar compressing... [${ jar} ]" )
97
+ from {
98
+ zipTree(file(jar))
99
+ }
100
+ }
101
+ } else {
102
+ println ' ⚠️ Skipping compression of dependency JAR files...'
103
+ }
51
104
}
52
105
53
106
// Add dependencies
54
107
dependencies {
108
+ // Add the dependencies listed in the gradle.yml file
109
+ if (! ngConfig. getJars(). isEmpty()) {
110
+ ngConfig. getJars(). each { jar ->
111
+ println (" 🔄 Jar mounting... [${ jar} ]" )
112
+ implementation files(jar)
113
+ }
114
+ } else {
115
+ println ' ⚠️ No JAR files specified in gradle.yml for dependencies.'
116
+ }
55
117
// Use the awesome Spock testing and specification framework
56
118
testImplementation libs. spock. core
57
119
// Incorporate JUnit Jupiter API version 4.13.2 for unit testing,
@@ -88,11 +150,4 @@ dependencies {
88
150
implementation group : ' com.jayway.jsonpath' , name : ' json-path' , version : ' 2.9.0'
89
151
// The "validation-api" library, version 2.0.1.Final, provides tools for validating Java objects according to defined constraints.
90
152
implementation group : ' javax.validation' , name : ' validation-api' , version : ' 2.0.1.Final'
91
-
92
- // unify4J: Java 1.8 skeleton library offering a rich toolkit of utility functions
93
- // for collections, strings, date/time, JSON, maps, and more.
94
- implementation files(' ./../libs/unify4j-v1.0.0.jar' )
95
- // alpha4j: is a Java 8 library featuring common data structures and algorithms.
96
- // Enhance your projects with efficient and easy-to-use implementations designed for performance and clarity.
97
- implementation files(' ./../libs/alpha4j-v1.0.0.jar' )
98
153
}
0 commit comments