groowt/web-view-components/build.gradle
2025-02-16 10:26:00 -06:00

148 lines
3.4 KiB
Groovy

import groovy.transform.NullCheck
plugins {
id 'groowt-conventions'
id 'groowt-antlr-plugin'
id 'groowt-testing'
id 'groowt-publish'
id 'java-library'
id 'groovy'
id 'java-test-fixtures'
}
repositories {
mavenCentral()
}
configurations {
groovyConsole
testFixturesApi {
extendsFrom configurations.testing
}
toolsImplementation {
extendsFrom(apiElements, runtimeElements)
}
}
sourceSets {
tools {
java {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
}
dependencies {
api libs.groovy
api project(':view-components')
api project(':views')
compileOnlyApi libs.jetbrains.anotations
implementation libs.slf4j.api
testRuntimeOnly project(':web-view-components-compiler')
groovyConsole libs.groovy.console
toolsImplementation libs.picocli
}
ext {
toolsPackageName = 'groowt.view.component.web.tools'
}
tasks.register('groovyConsole', JavaExec) {
group = 'groovy'
classpath += sourceSets.main.runtimeClasspath + configurations.groovyConsole
mainClass = 'groovy.console.ui.Console'
}
tasks.register('toolsJar', Jar) {
group 'tools'
archiveBaseName = 'web-tools'
exclude { FileTreeElement element ->
element.file in sourceSets.main.output
}
from sourceSets.tools.output
from sourceSets.tools.runtimeClasspath.filter(File.&exists).collect { it.isDirectory() ? it : zipTree(it) }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn tasks.named('jar')
}
@NullCheck
class ToolSpec {
final String name
final String mainClass
final String mainClassPackage
ToolSpec(String name, String mainClass, String mainClassPackage) {
this.name = name
this.mainClass = mainClass
this.mainClassPackage = mainClassPackage
}
String getFullMainClass() {
this.mainClassPackage + '.' + this.mainClass
}
}
def toolSpec = { String name, String mainClass ->
new ToolSpec(name, mainClass, project.ext.get('toolsPackageName') as String)
}
final List<ToolSpec> toolSpecs = [
toolSpec('astFileMaker', 'AstFileMakerCli'),
toolSpec('convertToGroovy', 'ConvertToGroovy'),
toolSpec('lexer', 'LexerTool'),
toolSpec('parser', 'ParserTool'),
toolSpec('parseTreeFileMaker', 'ParseTreeFileMakerCli'),
toolSpec('runTemplate', 'RunTemplate')
]
toolSpecs.each { spec ->
tasks.register("create${spec.name.capitalize()}StartScripts", CreateStartScripts) {
group = 'tools'
outputDir = file('bin')
applicationName = spec.name
mainClass = spec.fullMainClass
unixStartScriptGenerator.template = resources.text.fromFile('src/tools/binTemplate.gst')
dependsOn tasks.named('toolsJar')
}
}
tasks.register('createToolsStartScripts') {
group 'tools'
dependsOn tasks.matching { Task task ->
task != it
&& task.name.startsWith('create')
&& task.name.endsWith('StartScripts')
&& task.group == 'tools'
}
}
tasks.register('cleanBin', Delete) {
group = 'tools'
delete file('bin')
}
java {
withSourcesJar()
}
jar {
archiveBaseName = 'groowt-web-view-components'
}
publishing {
publications {
create('webViewComponents', MavenPublication) {
artifactId = 'web-view-components'
from components.java
}
}
}