Open salamanders opened 7 years ago
I think it is a great idea! I will need some days to look into and let you know
I got something working, but I have no idea if it has bad parts or redundant things or bad gradle practices. And I'm not sure how to have it build, deploy, and run all in one command (task?). But it worked!
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
sourceCompatibility = 1.7
version = '1.0'
compileJava.options.encoding = 'UTF-8'
mainClassName = 'info.benjaminhill.waller.RobotKt' // had to do a "main" outside of a class here
jar {
manifest {
attributes 'Implementation-Title': 'Waller', 'Implementation-Version': version, 'Main-Class': mainClassName
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
configurations {
sshAntTask
provided
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
main.compileClasspath += configurations.provided
test.compileClasspath += configurations.provided
test.runtimeClasspath += configurations.provided
}
repositories {
mavenCentral()
flatDir {
dirs '/Users/benjamin/Documents/leJOS_EV3_0.9.1-beta' + '/lib/ev3' // would be nice to not have to hardcode this
}
}
dependencies {
sshAntTask 'org.apache.ant:ant-jsch:1.10.1', 'jsch:jsch:0.1.29'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
provided group: 'lejos', name: 'ev3classes', version: '1.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" // I *think* jre7?
}
task deployEV3 {
doLast {
ant.taskdef(name: 'scp', classname: 'org.apache.tools.ant.taskdefs.optional.ssh.Scp', classpath: configurations.sshAntTask.asPath)
ant.scp(todir: ev3_username + '@' + ev3_server + ':/home/lejos/programs',
password: ev3_password,
trust: 'true',
verbose: 'true') {
fileset(dir: './build/libs') {
include(name: '**/*.jar')
}
}
}
}
buildscript {
ext.kotlin_version = '1.1.60'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.6" // but now 6 instead of 7?
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.6"
}
}
Sorry for the late feedback. It looks ok, but I would use as jvmTarget 1.7 (this is the version installed on Lejos).
You can use gradle clean build to build it (a good practice would be also to use Gradle Wrapper (https://docs.gradle.org/current/userguide/gradle_wrapper.html), i should include this in this example.
Did you try to deploy it to a mindstorm?
I did, and it worked!
I could put it in my own project, or add to yours - any preference?
PS: Got 1 suggestion from the kotlin board: https://discuss.kotlinlang.org/t/help-with-kotlin-on-lejos-lego-mindstorms-using-intellij-gradle/5421/2
I was trying to get your script (thank you!) and latest Kotlin working together so I could do Kotlin with Legos. I'm new to gradle scripts, and things like
plugins {... }
vsplugin ...
Do you know how to combine your example with https://github.com/JetBrains/kotlin-examples/blob/master/gradle/mixed-java-kotlin-hello-world/build.gradle ?