44 */
55// file:noinspection VulnerableLibrariesLocal
66// 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+ }
716
817plugins {
918 // Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
@@ -24,19 +33,58 @@ repositories {
2433 mavenCentral()
2534}
2635
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+ }
3179
3280// Define a task to build the Groovy library into a JAR
3381tasks. register(' buildGroovyJar' , Jar ) {
3482 // Set the base directory for the source files
3583 from ' src/main/groovy'
3684 // Set the destination directory for the compiled classes
3785 into(' ' )
38- archiveFileName = " ${ _name } " + " .jar"
39- version(" ${ _version } " )
86+ archiveFileName = " ${ ngConfig.getName() } " + " .jar"
87+ version(" ${ ngConfig.getVersion() } " )
4088 include ' **/*.groovy'
4189}
4290
@@ -46,12 +94,39 @@ tasks.named('build') {
4694}
4795
4896tasks. 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+ }
51115}
52116
53117// Add dependencies
54118dependencies {
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+ }
55130 // Use the awesome Spock testing and specification framework
56131 testImplementation libs. spock. core
57132 // Incorporate JUnit Jupiter API version 4.13.2 for unit testing,
0 commit comments