Skip to content

Commit

Permalink
📦 dependency: update CI.CD dependencies injection #3
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jun 27, 2024
1 parent 48d1c1b commit e7f8395
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 13 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ make jar

### Upgrading version

- file `gradle.properties`

```sh
ng.name=wizard4j
ng.version=v1.0.0
- file `gradle.yml`

```yaml
ng:
name: wizard4j
version: v1.0.0
enabled_link: false # enable compression and attachment of the external libraries
jars:
- enabled: false # enable compression and attachment of the external libraries
source: "" # lib Jar
- enabled: false
source: ""
```
## Integration
Expand Down
91 changes: 83 additions & 8 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
*/
//file:noinspection VulnerableLibrariesLocal
//file:noinspection SpellCheckingInspection
buildscript {
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
classpath 'org.yaml:snakeyaml:2.0'
}
}

plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
Expand All @@ -24,19 +33,58 @@ repositories {
mavenCentral()
}

def props = new Properties()
props.load(new FileInputStream(rootProject.file("gradle.properties")))
def _name = props.getProperty("ng.name")
def _version = props.getProperty("ng.version")
import org.yaml.snakeyaml.Yaml

class JarConfig {
boolean enabled
String source

JarConfig(Map<String, Object> config) {
enabled = config['enabled'] ?: false
source = config['source'] ?: ''
}
}

class NgConfig {
String name
String version
boolean enabledLink
List<JarConfig> jars

@SuppressWarnings('GroovyAssignabilityCheck')
NgConfig(Map<String, Object> configs) {
name = configs.containsKey('name') ? configs['name'] : 'bot4j'
version = configs.containsKey('version') ? configs['version'] : 'v0.0.0'
enabledLink = configs.containsKey('enabled_link') ? configs['enabled_link'] : false
// jars = configs.containsKey('jars') ? configs['jars'] : [] // List<String> jars
jars = configs.containsKey('jars') ? configs['jars'].collect { new JarConfig(it) } : []
}
}

// Define ngConfig as a static global variable
NgConfig ngConfig = loadNgConfig()

NgConfig loadNgConfig() {
def configs = file('gradle.yml')
if (configs.exists()) {
def yaml = new Yaml()
def config = yaml.load(new FileInputStream(configs))
println '⌛ Loading NgConfigs configuration via gradle.yml'
return new NgConfig(config['ng'] as Map<String, Object>)
} else {
println '⚠️ gradle.yml not found, using default configuration'
return new NgConfig(new HashMap<String, Object>())
}
}

// Define a task to build the Groovy library into a JAR
tasks.register('buildGroovyJar', Jar) {
// Set the base directory for the source files
from 'src/main/groovy'
// Set the destination directory for the compiled classes
into('')
archiveFileName = "${_name}" + ".jar"
version("${_version}")
archiveFileName = "${ngConfig.getName()}" + ".jar"
version("${ngConfig.getVersion()}")
include '**/*.groovy'
}

Expand All @@ -46,12 +94,39 @@ tasks.named('build') {
}

tasks.jar {
archivesBaseName = "${_name}"
version = "${_version}"
archivesBaseName = "${ngConfig.getName()}"
version = "${ngConfig.getVersion()}"

// Handle duplicates
// duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Compressing the external JAR files listed in gradle.yml using zipTree if enabled_link is true
if (ngConfig.isEnabledLink() && !ngConfig.getJars().isEmpty()) {
ngConfig.getJars().each { jar ->
if (jar.isEnabled() && !jar.getSource().isEmpty()) {
println("📦 Jar compressing... [${jar.getSource()}]")
from {
zipTree(file(jar.getSource()))
}
}
}
} else {
println '⚠️ Skipping compression of dependency JAR files...'
}
}

// Add dependencies
dependencies {
// Add the dependencies listed in the gradle.yml file
if (!ngConfig.getJars().isEmpty()) {
ngConfig.getJars().each { jar ->
if (!jar.getSource().isEmpty()) {
println("🔄 Jar mounting... [${jar.getSource()}]")
implementation files(jar.getSource())
}
}
} else {
println '⚠️ No JAR files specified in gradle.yml for dependencies.'
}
// Use the awesome Spock testing and specification framework
testImplementation libs.spock.core
// Incorporate JUnit Jupiter API version 4.13.2 for unit testing,
Expand Down
9 changes: 9 additions & 0 deletions plugin/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ng:
name: wizard4j
version: v1.0.0
enabled_link: false # enable compression and attachment of the external libraries
jars:
- enabled: false # enable compression and attachment of the external libraries
source: "" # lib Jar
- enabled: false
source: ""

0 comments on commit e7f8395

Please sign in to comment.