Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

build.gradle

Blame
  • build.gradle 6.06 KiB
    plugins {
        id 'java'
        id 'application'
        id 'maven-publish'
        id 'idea'
        id 'org.jastadd' version "${jastaddgradle_version}"
    }
    
    group 'de.tudresden.inf.st'
    
    ext {
        mainClassName = 'de.tudresden.inf.st.{{cookiecutter.repo_name}}.Main'
    }
    
    // set the main class name for `gradle run`
    application.mainClass = "${mainClassName}"
    
    java.toolchain.languageVersion = JavaLanguageVersion.of(11)
    
    repositories {
        mavenCentral()
        maven {
            name 'gitlab-maven'
            url 'https://git-st.inf.tu-dresden.de/api/v4/groups/jastadd/-/packages/maven'
        }
    }
    
    configurations {
        // add a configuration to store the grammar printing dependency in
        grammar2uml
    }
    
    File genSrc = file("src/gen/java")
    idea.module.generatedSourceDirs += genSrc
    sourceSets.main.java.srcDir genSrc
    
    dependencies {
        // uncomment if relast2uml should be used; this requires graphviz in CI and on system
        // implementation group: 'de.tudresden.inf.st', name: 'dumpAstWithPlantuml', version: "${relast2uml_version}"
        grammar2uml group: 'de.tudresden.inf.st', name: 'grammar2uml', version: "${grammar2uml_version}"
        testImplementation group: 'org.assertj', name: 'assertj-core', version: "${assertj_version}"
        testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${jupyter_version}"
        testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${jupyter_version}"
    }
    
    def versionFile = 'src/main/resources/{{cookiecutter.repo_name}}Version.properties'
    def oldProps = new Properties()
    
    try {
        file(versionFile).withInputStream { stream -> oldProps.load(stream) }
        version = oldProps['version']
    } catch (e) {
        // this happens, if either the properties file is not present, or cannot be read from
        throw new GradleException("File ${versionFile} not found or unreadable. Aborting.", e)
    }
    
    task printVersion() {
        doLast {
            println(version)
        }
    }
    
    task newVersion() {
        doFirst {
            def props = new Properties()
            props['version'] = value
            props.store(file(versionFile).newWriter(), null)
        }
    }
    
    test {
        testLogging.showStandardStreams = true
        useJUnitPlatform()
    }
    
    jar {
        manifest {
            attributes 'Main-Class': '${mainClassName}'
        }
    
        from {
            configurations.runtimeClasspath.collect { return (it.isDirectory() ? it : zipTree(it)) }
        }
    }
    
    def relastJar = 'libs/relast.jar'
    def relastFiles = ['./src/main/jastadd/{{cookiecutter.project_short_name}}.relast']
    def grammarPrefix = './src/gen/jastadd/{{cookiecutter.project_short_name}}'
    def grammarDiagramFile = './src/gen/resources/{{cookiecutter.project_short_name}}Grammar.png'
    def jastAddListName = 'JastAddList'
    
    task generateGrammarDiagrams(type: JavaExec) {
        group = 'Documentation'
        classpath = configurations.grammar2uml
    
        args "--output=${grammarDiagramFile}", '--defaultFolders'
        args relastFiles
    
        inputs.files relastFiles
        outputs.files file(grammarDiagramFile)
    }
    
    task relastToJastAdd(type: JavaExec) {
        group = 'Build'
        classpath = files("${relastJar}")
    
        args "--grammarName=${grammarPrefix}",
                '--useJastAddNames',
                '--listClass=java.util.ArrayList',
                "--jastAddList=${jastAddListName}",
                '--file'
        args relastFiles
    
        inputs.files relastFiles
        outputs.files file("${grammarPrefix}.ast"), file("${grammarPrefix}.jadd")
    }
    
    jastadd {
        configureModuleBuild()
        modules {
            //noinspection GroovyAssignabilityCheck
            module('relast-module') {
    
                java {
                    basedir 'src/'
                    include 'main/**/*.java'
                    include 'gen/**/*.java'
                }
    
                jastadd {
                    basedir 'src/'
                    include 'main/jastadd/**/*.ast'
                    include 'main/jastadd/**/*.jadd'
                    include 'main/jastadd/**/*.jrag'
                    include 'gen/jastadd/**/*.ast'
                    include 'gen/jastadd/**/*.jadd'
                    include 'gen/jastadd/**/*.jrag'
                }
    
                scanner {
                    // TODO add scanner here
                    // include 'src/main/jastadd/scanner/Scanner.flex'
                }
    
                parser {
                    // TODO add parser here
                    // include 'src/main/jastadd/parser/Parser.parser'
                }
            }
        }
    
        cleanGen.doFirst {
            delete 'src/gen/'
            delete 'src/gen-res/'
        }
    
        // TODO uncomment of parser is used
        // parser.name = '{{cookiecutter.project_short_name}}Parser'
        // scanner.genDir = 'src/gen/java/de/tudresden/inf/st/{{cookiecutter.repo_name}}/scanner'
        // parser.genDir = 'src/gen/java/de/tudresden/inf/st/{{cookiecutter.repo_name}}/parser'
    
        module = 'relast-module'
        astPackage = 'de.tudresden.inf.st.{{cookiecutter.repo_name}}.ast'
        genDir = 'src/gen/java'
        buildInfoDir = 'src/gen-res'
    
        // default options are: '--rewrite=cnta', '--safeLazy', '--visitCheck=false', '--cacheCycle=false'
        extraJastAddOptions = ["--List=${jastAddListName}"]
    }
    
    
    // publish gitlab project
    publishing {
        publications {
            maven(MavenPublication) {
                artifactId = '{{cookiecutter.repo_name}}'
                // from components.java
                artifact("build/libs/{{cookiecutter.repo_name}}-${version}.jar") {
                    extension 'jar'
                }
            }
        }
        repositories {
            maven {
                url "https://git-st.inf.tu-dresden.de/api/v4/projects/$System.env.CI_PROJECT_ID/packages/maven"
                // Uncomment the following lines to publish manually (and comment out the other credentials section)
    //            credentials(HttpHeaderCredentials) {
    //                name = "Private-Token"
    //                value = gitLabPrivateToken // the variable resides in ~/.gradle/gradle.properties
    //            }
                credentials(HttpHeaderCredentials) {
                    name = 'Job-Token'
                    value = System.getenv("CI_JOB_TOKEN")
                }
                authentication {
                    header(HttpHeaderAuthentication)
                }
            }
    
        }
    }
    
    // Workflow configuration for phases
    clean.dependsOn cleanGen
    generateAst.dependsOn relastToJastAdd
    publish.dependsOn jar