calculator-gradle/build.gradle

143 lines
4.2 KiB
Groovy
Raw Normal View History

2024-11-13 18:56:35 +01:00
import org.gradle.api.tasks.compile.GroovyCompile
// Configure buildscript
buildscript {
dependencies{
classpath files('libs/plugins/gradle-one-jar-1.0.6-gradle7ported.jar')
}
}
apply plugin: 'java'
apply plugin: 'groovy'
def mainClassEnabled = applicationMainClassName != "none"
compileJava.options.encoding = 'UTF-8'
// Run Configuration
if (mainClassEnabled) {
apply plugin: 'application'
apply plugin: com.github.rholder.gradle.GradleOneJarPlugin
mainClassName = applicationMainClassName
// Run Configuration
def runningDir = new File('run/')
runningDir.mkdirs()
run.workingDir = runningDir
run.defaultCharacterEncoding = "UTF-8"
run.systemProperty("file.encoding", "UTF-8")
run.jvmArgs << "-XX:+ShowCodeDetailsInExceptionMessages"
}
group projectArtifactGroup
version projectArtifactVersion
sourceCompatibility = projectJavaMinVersion
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url 'https://nexus.tswf.io/repository/maven-releases' }
maven { url 'https://jitpack.io' }
maven { url 'https://git.tswf.io/api/packages/public-repos/maven'}
}
dependencies {
// Groovy
// Uncomment to use groovy 3
// implementation 'org.codehaus.groovy:groovy-all:3.0.5'
implementation group: 'org.apache.groovy', name: 'groovy', version: '4.0.9'
// Better Groovy
implementation 'io.tswf.groovy.better-groovy:better-groovy-core:1.+'
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.26'
annotationProcessor 'org.projectlombok:lombok:1.18.26'
// Local 'libs' folder
implementation fileTree(dir: 'libs/jar', include: '*.jar')
compileOnly fileTree(dir: 'libs/compile-jar', include: '*.jar')
annotationProcessor fileTree(dir: 'libs/jar', include: '*.jar')
annotationProcessor fileTree(dir: 'libs/compile-jar', include: '*.jar')
compileOnly 'com.google.auto.service:auto-service:1.0.1'
annotationProcessor 'com.google.auto.service:auto-service:1.0.1'
// Other
}
sourceSets {
// Groovy extensions source set
extension {
groovy {
compileClasspath += main.compileClasspath
}
}
// Main source set
main {
groovy {
compileClasspath += extension.output
runtimeClasspath += extension.output
}
}
}
// Apply to all groovy source sets
tasks.withType(GroovyCompile).each {task ->
task.doFirst {
// Append compile classpath to groovy classpath to access compile classpath dependencies in compiler configuration script
it.groovyClasspath += it.classpath
// Transfers all groovyc options to compiler configuration script as system properties that can be accessed via System.getProperty("name") from the script file
for (def property : project.properties) {
if (property.key.startsWith("groovycOption")) {
task.groovyOptions.forkOptions.jvmArgs += "-D${property.key}=${property.value}" as String
}
}
println "Building ${it.name} with groovy classpath: ${it.groovyClasspath.files}"
println "Building ${it.name} with classpath ${it.classpath.files}"
}
task.groovyOptions.javaAnnotationProcessing = true
task.options.encoding = "UTF-8"
task.groovyOptions.configurationScript = file('gradle/config/groovyc-static.groovy')
}
jar {
from (
sourceSets.extension.output,
sourceSets.main.output
)
}
if (mainClassEnabled) {
// Creates all-in-one jar which contains all dependencies
task buildJarInJarAllInOneJar(type: OneJar) {
mainClass = mainClassName
archiveFileName.set("$projectArtifactId-$projectArtifactVersion-jij-all-in-one.jar")
}
}
// Creates all-in-one jar which contains all dependencies extracted from it jars and added directly to result jar as zip entries
task buildExtractedAllInOneJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
manifest {
attributes 'Main-Class': applicationMainClassName
}
archiveFileName.set("$projectArtifactId-$projectArtifactVersion-extracted-all-in-one.jar")
// Adds dependencies and extensions to output Jar
from {
sourceSets.extension.output
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}