buildscript { repositories { mavenCentral() } dependencies { classpath 'net.sf.proguard:proguard-gradle:6.0.1' } } plugins { id "java" id "com.github.johnrengelman.shadow" version "2.0.2" id "org.sonarqube" version "2.6.2" } import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import proguard.gradle.ProGuardTask sourceCompatibility = '1.8' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' if (!hasProperty('mainClass')) { ext.mainClass = 'com.annimon.ownlang.Main' } ext.generatedJavaDir = "${rootProject.projectDir}/src/main/generatedJava" sourceSets.main.java.srcDirs += project.generatedJavaDir repositories { jcenter() } task generateJavaSources() { doLast { def source = """ package com.annimon.ownlang; class Gen { private Gen() {} public static final String BUILD_DATE = "${new Date().format('YYMMdd')}"; } """ def genFile = new File("${project.generatedJavaDir}/com/annimon/ownlang/Gen.java") genFile.getParentFile().mkdirs() genFile.write(source) } } compileJava.dependsOn(generateJavaSources) task run(dependsOn: classes, type: JavaExec) { main = project.mainClass classpath = sourceSets.main.runtimeClasspath standardInput = System.in ignoreExitValue = true } task runOptimizing(dependsOn: classes, type: JavaExec) { main = project.mainClass classpath = sourceSets.main.runtimeClasspath ignoreExitValue = true // args '-o 9 -m -a -f examples/game/minesweeper.own'.split(' ') args '-o 9 -m -a -f program.own'.split(' ') } task dist(type: ShadowJar) { from sourceSets.main.output configurations = [project.configurations.runtime] destinationDir file("$rootProject.projectDir/dist") exclude 'META-INF/*.DSA' exclude 'META-INF/*.RSA' exclude 'META-INF/maven/**' exclude 'LICENSE*' manifest.attributes( 'Main-Class': project.mainClass, 'Build-Date': new Date().format('YYMMdd') ) } task proguard(dependsOn: dist, type: ProGuardTask) { configuration "$rootProject.projectDir/proguard.properties" injars "$rootProject.projectDir/dist/OwnLang.jar" outjars "$rootProject.projectDir/store/OwnLang.jar" // Automatically handle the Java version of this build. if (System.getProperty('java.version').startsWith('1.')) { // Before Java 9, the runtime classes were packaged in a single jar file. libraryjars "${System.getProperty('java.home')}/lib/rt.jar" } else { // As of Java 9, the runtime classes are packaged in modular jmod files. def jmods = files { file("${System.getProperty('java.home')}/jmods").listFiles() } jmods.each { libraryjars it, jarfilter: '!**.jar', filter: '!module-info.class' } } } task sandbox(dependsOn: proguard, type: Jar) { from zipTree("$rootProject.projectDir/store/OwnLang.jar") libsDirName = "$rootProject.projectDir/store" appendix = "Sandbox" exclude "**/modules/canvas/**", "**/modules/canvasfx/**", "**/modules/forms/**", "**/modules/java/**", "**/modules/jdbc/**", "**/modules/robot/**", "**/modules/okhttp/**", "**/modules/socket/**", "io/**", "**/modules/aimp/**", "aimpremote/**", "**/modules/downloader/**", "**/modules/zip/**", "**/modules/gzip/**", "jline/**", "org/fusesource/**", "META-INF/native/**" manifest { attributes 'Main-Class': project.mainClass } } dependencies { compile ('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } compile 'org.json:json:20180130' compile 'org.yaml:snakeyaml:1.20' compile 'jline:jline:2.14.5' testImplementation 'junit:junit:4.12' testImplementation 'org.openjdk.jmh:jmh-core:1.13' testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:1.13' } sonarqube { properties { property "sonar.projectName", "Own-Programming-Language-Tutorial" property "sonar.projectKey", "aNNiMON_Own-Programming-Language-Tutorial" property "sonar.host.url", "https://sonarcloud.io" } } test { testLogging { events "passed", "skipped", "failed" exceptionFormat "full" } }